Fixed #1273 - Support for Filtering, Sorting and Cell Editing on DataTable
parent
1a72acabb5
commit
044290601e
|
@ -2,7 +2,7 @@
|
||||||
<td :style="containerStyle" :class="containerClass" @click="onClick" @keydown="onKeyDown" role="cell">
|
<td :style="containerStyle" :class="containerClass" @click="onClick" @keydown="onKeyDown" role="cell">
|
||||||
<span v-if="responsiveLayout === 'stack'" class="p-column-title">{{columnProp('header')}}</span>
|
<span v-if="responsiveLayout === 'stack'" class="p-column-title">{{columnProp('header')}}</span>
|
||||||
<component :is="column.children.body" :data="rowData" :column="column" :index="rowIndex" :frozenRow="frozenRow" v-if="column.children && column.children.body && !d_editing" />
|
<component :is="column.children.body" :data="rowData" :column="column" :index="rowIndex" :frozenRow="frozenRow" v-if="column.children && column.children.body && !d_editing" />
|
||||||
<component :is="column.children.editor" :data="rowData" :column="column" :index="rowIndex" :frozenRow="frozenRow" v-else-if="column.children && column.children.editor && d_editing" />
|
<component :is="column.children.editor" :data="editingRowData" :column="column" :index="rowIndex" :frozenRow="frozenRow" v-else-if="column.children && column.children.editor && d_editing" />
|
||||||
<template v-else-if="columnProp('selectionMode')">
|
<template v-else-if="columnProp('selectionMode')">
|
||||||
<DTRadioButton :value="rowData" :checked="selected" @change="toggleRowWithRadio" v-if="columnProp('selectionMode') === 'single'" />
|
<DTRadioButton :value="rowData" :checked="selected" @change="toggleRowWithRadio" v-if="columnProp('selectionMode') === 'single'" />
|
||||||
<DTCheckbox :value="rowData" :checked="selected" @change="toggleRowWithCheckbox" v-else-if="columnProp('selectionMode') ==='multiple'" />
|
<DTCheckbox :value="rowData" :checked="selected" @change="toggleRowWithCheckbox" v-else-if="columnProp('selectionMode') ==='multiple'" />
|
||||||
|
@ -39,7 +39,7 @@ import Ripple from 'primevue/ripple';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BodyCell',
|
name: 'BodyCell',
|
||||||
emits: ['cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel', 'row-edit-init', 'row-edit-save', 'row-edit-cancel', 'editing-cell-change',
|
emits: ['cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel', 'row-edit-init', 'row-edit-save', 'row-edit-cancel',
|
||||||
'row-toggle', 'radio-change', 'checkbox-change'],
|
'row-toggle', 'radio-change', 'checkbox-change'],
|
||||||
props: {
|
props: {
|
||||||
rowData: {
|
rowData: {
|
||||||
|
@ -157,7 +157,6 @@ export default {
|
||||||
switchCellToViewMode() {
|
switchCellToViewMode() {
|
||||||
this.d_editing = false;
|
this.d_editing = false;
|
||||||
this.unbindDocumentEditListener();
|
this.unbindDocumentEditListener();
|
||||||
this.$emit('editing-cell-change', {rowIndex: this.rowIndex, cellIndex: this.index, editing: false});
|
|
||||||
OverlayEventBus.off('overlay-click', this.overlayEventListener);
|
OverlayEventBus.off('overlay-click', this.overlayEventListener);
|
||||||
this.overlayEventListener = null;
|
this.overlayEventListener = null;
|
||||||
},
|
},
|
||||||
|
@ -169,7 +168,6 @@ export default {
|
||||||
this.d_editing = true;
|
this.d_editing = true;
|
||||||
this.bindDocumentEditListener();
|
this.bindDocumentEditListener();
|
||||||
this.$emit('cell-edit-init', {originalEvent: event, data: this.rowData, field: this.columnProp('field'), index: this.rowIndex});
|
this.$emit('cell-edit-init', {originalEvent: event, data: this.rowData, field: this.columnProp('field'), index: this.rowIndex});
|
||||||
this.$emit('editing-cell-change', {rowIndex: this.rowIndex, cellIndex: this.index, editing: true});
|
|
||||||
|
|
||||||
this.overlayEventListener = (e) => {
|
this.overlayEventListener = (e) => {
|
||||||
if (this.$el && this.$el.contains(e.target)) {
|
if (this.$el && this.$el.contains(e.target)) {
|
||||||
|
@ -181,9 +179,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
completeEdit(event, type) {
|
completeEdit(event, type) {
|
||||||
let completeEvent = {
|
const completeEvent = {
|
||||||
originalEvent: event,
|
originalEvent: event,
|
||||||
data: this.rowData,
|
data: this.rowData,
|
||||||
|
newData: this.editingRowData,
|
||||||
field: this.columnProp('field'),
|
field: this.columnProp('field'),
|
||||||
index: this.rowIndex,
|
index: this.rowIndex,
|
||||||
type: type,
|
type: type,
|
||||||
|
@ -328,6 +327,9 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
editingRowData() {
|
||||||
|
return this.d_editing ? {...this.rowData} : this.rowData;
|
||||||
|
},
|
||||||
containerClass() {
|
containerClass() {
|
||||||
return [this.columnProp('bodyClass'), this.columnProp('class'), {
|
return [this.columnProp('bodyClass'), this.columnProp('class'), {
|
||||||
'p-selection-column': this.columnProp('selectionMode') != null,
|
'p-selection-column': this.columnProp('selectionMode') != null,
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
||||||
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
||||||
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
||||||
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)" @editing-cell-change="onEditingCellChange($event)"/>
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)" />
|
||||||
<DTTableBody :value="dataToRender" :columns="columns" :empty="empty" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
<DTTableBody :value="dataToRender" :columns="columns" :empty="empty" :dataKey="dataKey" :selection="selection" :selectionKeys="d_selectionKeys" :selectionMode="selectionMode" :contextMenu="contextMenu" :contextMenuSelection="contextMenuSelection"
|
||||||
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy" :scrollable="scrollable"
|
:rowGroupMode="rowGroupMode" :groupRowsBy="groupRowsBy" :expandableRowGroups="expandableRowGroups" :rowClass="rowClass" :editMode="editMode" :compareSelectionBy="compareSelectionBy" :scrollable="scrollable"
|
||||||
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
:expandedRowIcon="expandedRowIcon" :collapsedRowIcon="collapsedRowIcon" :expandedRows="expandedRows" :expandedRowKeys="d_expandedRowKeys" :expandedRowGroups="expandedRowGroups"
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
@row-mousedown="onRowMouseDown" @row-dragstart="onRowDragStart($event)" @row-dragover="onRowDragOver($event)" @row-dragleave="onRowDragLeave($event)" @row-dragend="onRowDragEnd($event)" @row-drop="onRowDrop($event)"
|
||||||
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
@row-toggle="toggleRow($event)" @radio-change="toggleRowWithRadio($event)" @checkbox-change="toggleRowWithCheckbox($event)"
|
||||||
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
||||||
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)" @editing-cell-change="onEditingCellChange($event)"/>
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)" />
|
||||||
<DTTableFooter :columnGroup="footerColumnGroup" :columns="columns" />
|
<DTTableFooter :columnGroup="footerColumnGroup" :columns="columns" />
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -77,7 +77,7 @@ export default {
|
||||||
'update:selection', 'row-select', 'row-unselect', 'update:contextMenuSelection', 'row-contextmenu', 'row-unselect-all', 'row-select-all',
|
'update:selection', 'row-select', 'row-unselect', 'update:contextMenuSelection', 'row-contextmenu', 'row-unselect-all', 'row-select-all',
|
||||||
'column-resize-end', 'column-reorder', 'row-reorder', 'update:expandedRows', 'row-collapse', 'row-expand',
|
'column-resize-end', 'column-reorder', 'row-reorder', 'update:expandedRows', 'row-collapse', 'row-expand',
|
||||||
'update:expandedRowGroups', 'rowgroup-collapse', 'rowgroup-expand', 'update:filters', 'state-restore', 'state-save',
|
'update:expandedRowGroups', 'rowgroup-collapse', 'rowgroup-expand', 'update:filters', 'state-restore', 'state-save',
|
||||||
'cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel', 'update:editingRows', 'row-edit-init', 'row-edit-save', 'row-edit-cancel', 'editing-cell-change'],
|
'cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel', 'update:editingRows', 'row-edit-init', 'row-edit-save', 'row-edit-cancel'],
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
@ -328,8 +328,7 @@ export default {
|
||||||
d_expandedRowKeys: null,
|
d_expandedRowKeys: null,
|
||||||
d_columnOrder: null,
|
d_columnOrder: null,
|
||||||
d_editingRowKeys: null,
|
d_editingRowKeys: null,
|
||||||
d_filters: this.cloneFilters(this.filters),
|
d_filters: this.cloneFilters(this.filters)
|
||||||
d_editingCells: []
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
rowTouched: false,
|
rowTouched: false,
|
||||||
|
@ -1585,18 +1584,6 @@ export default {
|
||||||
onCellEditCancel(event) {
|
onCellEditCancel(event) {
|
||||||
this.$emit('cell-edit-cancel', event);
|
this.$emit('cell-edit-cancel', event);
|
||||||
},
|
},
|
||||||
onEditingCellChange(event) {
|
|
||||||
let { rowIndex, cellIndex, editing } = event;
|
|
||||||
let _editingCells = [...this.d_editingCells];
|
|
||||||
|
|
||||||
if (editing)
|
|
||||||
_editingCells.push({ rowIndex, cellIndex });
|
|
||||||
else
|
|
||||||
_editingCells = _editingCells.filter(cell => !(cell.rowIndex === rowIndex && cell.cellIndex === cellIndex));
|
|
||||||
|
|
||||||
this.d_editingCells = _editingCells;
|
|
||||||
this.$emit('value-change', this.processedData);
|
|
||||||
},
|
|
||||||
onRowEditInit(event) {
|
onRowEditInit(event) {
|
||||||
let _editingRows = this.editingRows ? [...this.editingRows] : [];
|
let _editingRows = this.editingRows ? [...this.editingRows] : [];
|
||||||
_editingRows.push(event.data);
|
_editingRows.push(event.data);
|
||||||
|
@ -1794,13 +1781,10 @@ export default {
|
||||||
hasFilters() {
|
hasFilters() {
|
||||||
return this.filters && Object.keys(this.filters).length > 0 && this.filters.constructor === Object;
|
return this.filters && Object.keys(this.filters).length > 0 && this.filters.constructor === Object;
|
||||||
},
|
},
|
||||||
hasEditingCell() {
|
|
||||||
return this.d_editingCells && this.d_editingCells.length !== 0;
|
|
||||||
},
|
|
||||||
processedData() {
|
processedData() {
|
||||||
let data = this.value || [];
|
let data = this.value || [];
|
||||||
|
|
||||||
if (!this.lazy && !this.hasEditingCell) {
|
if (!this.lazy) {
|
||||||
if (data && data.length) {
|
if (data && data.length) {
|
||||||
if (this.sorted) {
|
if (this.sorted) {
|
||||||
if(this.sortMode === 'single')
|
if(this.sortMode === 'single')
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
:editMode="editMode" :editing="editMode === 'row' && isRowEditing(rowData)" :responsiveLayout="responsiveLayout"
|
:editMode="editMode" :editing="editMode === 'row' && isRowEditing(rowData)" :responsiveLayout="responsiveLayout"
|
||||||
@radio-change="onRadioChange($event)" @checkbox-change="onCheckboxChange($event)" @row-toggle="onRowToggle($event)"
|
@radio-change="onRadioChange($event)" @checkbox-change="onCheckboxChange($event)" @row-toggle="onRowToggle($event)"
|
||||||
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
@cell-edit-init="onCellEditInit($event)" @cell-edit-complete="onCellEditComplete($event)" @cell-edit-cancel="onCellEditCancel($event)"
|
||||||
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)" @editing-cell-change="onEditingCellChange($event)"/>
|
@row-edit-init="onRowEditInit($event)" @row-edit-save="onRowEditSave($event)" @row-edit-cancel="onRowEditCancel($event)" />
|
||||||
</template>
|
</template>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="p-datatable-row-expansion" v-if="templates['expansion'] && expandedRows && isRowExpanded(rowData)" :key="getRowKey(rowData, index) + '_expansion'" role="row">
|
<tr class="p-datatable-row-expansion" v-if="templates['expansion'] && expandedRows && isRowExpanded(rowData)" :key="getRowKey(rowData, index) + '_expansion'" role="row">
|
||||||
|
@ -52,7 +52,7 @@ export default {
|
||||||
emits: ['rowgroup-toggle', 'row-click', 'row-dblclick', 'row-rightclick', 'row-touchend', 'row-keydown', 'row-mousedown',
|
emits: ['rowgroup-toggle', 'row-click', 'row-dblclick', 'row-rightclick', 'row-touchend', 'row-keydown', 'row-mousedown',
|
||||||
'row-dragstart', 'row-dragover', 'row-dragleave', 'row-dragend', 'row-drop', 'row-toggle',
|
'row-dragstart', 'row-dragover', 'row-dragleave', 'row-dragend', 'row-drop', 'row-toggle',
|
||||||
'radio-change', 'checkbox-change', 'cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel',
|
'radio-change', 'checkbox-change', 'cell-edit-init', 'cell-edit-complete', 'cell-edit-cancel',
|
||||||
'row-edit-init', 'row-edit-save', 'row-edit-cancel', 'editing-cell-change'],
|
'row-edit-init', 'row-edit-save', 'row-edit-cancel'],
|
||||||
props: {
|
props: {
|
||||||
value: {
|
value: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
@ -447,9 +447,6 @@ export default {
|
||||||
onRowEditCancel(event) {
|
onRowEditCancel(event) {
|
||||||
this.$emit('row-edit-cancel', event);
|
this.$emit('row-edit-cancel', event);
|
||||||
},
|
},
|
||||||
onEditingCellChange(event) {
|
|
||||||
this.$emit('editing-cell-change', event);
|
|
||||||
},
|
|
||||||
updateFrozenRowStickyPosition() {
|
updateFrozenRowStickyPosition() {
|
||||||
this.$el.style.top = DomHandler.getOuterHeight(this.$el.previousElementSibling) + 'px';
|
this.$el.style.top = DomHandler.getOuterHeight(this.$el.previousElementSibling) + 'px';
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue