diff --git a/components/lib/datatable/BaseDataTable.vue b/components/lib/datatable/BaseDataTable.vue
index d307f759b..ebdee7533 100644
--- a/components/lib/datatable/BaseDataTable.vue
+++ b/components/lib/datatable/BaseDataTable.vue
@@ -167,7 +167,7 @@ export default {
default: false
},
expandedRows: {
- type: Array,
+ type: [Array, Object],
default: null
},
expandedRowIcon: {
diff --git a/components/lib/datatable/BodyRow.vue b/components/lib/datatable/BodyRow.vue
new file mode 100644
index 000000000..227413575
--- /dev/null
+++ b/components/lib/datatable/BodyRow.vue
@@ -0,0 +1,575 @@
+
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+ |
+
+
+
+
+ |
+
+
+
+
+
+ |
+
+
+
+
diff --git a/components/lib/datatable/DataTable.vue b/components/lib/datatable/DataTable.vue
index 96d4f4ef0..e7fd50923 100755
--- a/components/lib/datatable/DataTable.vue
+++ b/components/lib/datatable/DataTable.vue
@@ -124,7 +124,6 @@
:expandedRowIcon="expandedRowIcon"
:collapsedRowIcon="collapsedRowIcon"
:expandedRows="expandedRows"
- :expandedRowKeys="d_expandedRowKeys"
:expandedRowGroups="expandedRowGroups"
:editingRows="editingRows"
:editingRowKeys="d_editingRowKeys"
@@ -181,7 +180,6 @@
:expandedRowIcon="expandedRowIcon"
:collapsedRowIcon="collapsedRowIcon"
:expandedRows="expandedRows"
- :expandedRowKeys="d_expandedRowKeys"
:expandedRowGroups="expandedRowGroups"
:editingRows="editingRows"
:editingRowKeys="d_editingRowKeys"
@@ -345,7 +343,6 @@ export default {
d_multiSortMeta: this.multiSortMeta ? [...this.multiSortMeta] : [],
d_groupRowsSortMeta: null,
d_selectionKeys: null,
- d_expandedRowKeys: null,
d_columnOrder: null,
d_editingRowKeys: null,
d_editingMeta: {},
@@ -396,11 +393,6 @@ export default {
}
}
},
- expandedRows(newValue) {
- if (this.dataKey) {
- this.updateExpandedRowKeys(newValue);
- }
- },
editingRows: {
immediate: true,
handler(newValue) {
@@ -1087,17 +1079,6 @@ export default {
this.d_selectionKeys[String(ObjectUtils.resolveFieldData(selection, this.dataKey))] = 1;
}
},
- updateExpandedRowKeys(expandedRows) {
- if (expandedRows && expandedRows.length) {
- this.d_expandedRowKeys = {};
-
- for (let data of expandedRows) {
- this.d_expandedRowKeys[String(ObjectUtils.resolveFieldData(data, this.dataKey))] = 1;
- }
- } else {
- this.d_expandedRowKeys = null;
- }
- },
updateEditingRowKeys(editingRows) {
if (editingRows && editingRows.length) {
this.d_editingRowKeys = {};
@@ -1557,31 +1538,22 @@ export default {
event.preventDefault();
},
toggleRow(event) {
- let rowData = event.data;
- let expanded;
- let expandedRowIndex;
- let _expandedRows = this.expandedRows ? [...this.expandedRows] : [];
+ const { expanded, ...rest } = event;
+ const rowData = event.data;
+ let expandedRows;
if (this.dataKey) {
- expanded = this.d_expandedRowKeys ? this.d_expandedRowKeys[ObjectUtils.resolveFieldData(rowData, this.dataKey)] !== undefined : false;
+ const value = ObjectUtils.resolveFieldData(rowData, this.dataKey);
+
+ expandedRows = this.expandedRows ? { ...this.expandedRows } : {};
+ expanded ? (expandedRows[value] = true) : delete expandedRows[value];
} else {
- expandedRowIndex = this.findIndex(rowData, this.expandedRows);
- expanded = expandedRowIndex > -1;
+ expandedRows = this.expandedRows ? [...this.expandedRows] : [];
+ expanded ? expandedRows.push(rowData) : (expandedRows = expandedRows.filter((d) => !this.equals(rowData, d)));
}
- if (expanded) {
- if (expandedRowIndex == null) {
- expandedRowIndex = this.findIndex(rowData, this.expandedRows);
- }
-
- _expandedRows.splice(expandedRowIndex, 1);
- this.$emit('update:expandedRows', _expandedRows);
- this.$emit('row-collapse', event);
- } else {
- _expandedRows.push(rowData);
- this.$emit('update:expandedRows', _expandedRows);
- this.$emit('row-expand', event);
- }
+ this.$emit('update:expandedRows', expandedRows);
+ expanded ? this.$emit('row-expand', rest) : this.$emit('row-collapse', rest);
},
toggleRowGroup(e) {
const event = e.originalEvent;
@@ -1655,7 +1627,6 @@ export default {
if (this.expandedRows) {
state.expandedRows = this.expandedRows;
- state.expandedRowKeys = this.d_expandedRowKeys;
}
if (this.expandedRowGroups) {
@@ -1717,7 +1688,6 @@ export default {
}
if (restoredState.expandedRows) {
- this.d_expandedRowKeys = restoredState.expandedRowKeys;
this.$emit('update:expandedRows', restoredState.expandedRows);
}
diff --git a/components/lib/datatable/TableBody.vue b/components/lib/datatable/TableBody.vue
index 72383249b..743290cd3 100755
--- a/components/lib/datatable/TableBody.vue
+++ b/components/lib/datatable/TableBody.vue
@@ -1,128 +1,78 @@
-
-
-
-
-
- |
-
-
-
-
-
-
-
-
-
- |
-
-
-
-
- |
-
+
+
-
-
-
- |
-
+
diff --git a/components/lib/datatable/style/DataTableStyle.js b/components/lib/datatable/style/DataTableStyle.js
index 1b46d9c72..ae45cb41a 100644
--- a/components/lib/datatable/style/DataTableStyle.js
+++ b/components/lib/datatable/style/DataTableStyle.js
@@ -368,7 +368,7 @@ const classes = {
rowgroupHeader: 'p-rowgroup-header',
rowGroupToggler: 'p-row-toggler p-link',
rowGroupTogglerIcon: 'p-row-toggler-icon',
- row: ({ instance, props, rowData }) => {
+ row: ({ instance, props }) => {
let rowStyleClass = [];
if (props.selectionMode) {
@@ -377,13 +377,13 @@ const classes = {
if (props.selection) {
rowStyleClass.push({
- 'p-highlight': instance.isSelected(rowData)
+ 'p-highlight': instance.isSelected
});
}
if (props.contextMenuSelection) {
rowStyleClass.push({
- 'p-highlight-contextmenu': instance.isSelectedWithContextMenu(rowData)
+ 'p-highlight-contextmenu': instance.isSelectedWithContextMenu
});
}
diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js
index e8e23f106..a6c1f5e10 100755
--- a/components/lib/utils/ObjectUtils.js
+++ b/components/lib/utils/ObjectUtils.js
@@ -203,13 +203,15 @@ export default {
},
getVNodeProp(vnode, prop) {
- let props = vnode.props;
+ if (vnode) {
+ let props = vnode.props;
- if (props) {
- let kebabProp = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
- let propName = Object.prototype.hasOwnProperty.call(props, kebabProp) ? kebabProp : prop;
+ if (props) {
+ let kebabProp = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
+ let propName = Object.prototype.hasOwnProperty.call(props, kebabProp) ? kebabProp : prop;
- return vnode.type.extends.props[prop].type === Boolean && props[propName] === '' ? true : props[propName];
+ return vnode.type.extends.props[prop].type === Boolean && props[propName] === '' ? true : props[propName];
+ }
}
return null;
diff --git a/doc/datatable/RowExpansionDoc.vue b/doc/datatable/RowExpansionDoc.vue
index e429a3b26..dbda2780c 100644
--- a/doc/datatable/RowExpansionDoc.vue
+++ b/doc/datatable/RowExpansionDoc.vue
@@ -223,7 +223,7 @@ export default {
this.$toast.add({ severity: 'success', summary: 'Product Collapsed', detail: event.data.name, life: 3000 });
},
expandAll() {
- this.expandedRows = this.products.filter((p) => p.id);
+ this.expandedRows = this.products.reduce((acc, p) => (acc[p.id] = true) && acc, {});
},
collapseAll() {
this.expandedRows = null;
@@ -352,7 +352,7 @@ const onRowCollapse = (event) => {
toast.add({ severity: 'success', summary: 'Product Collapsed', detail: event.data.name, life: 3000 });
};
const expandAll = () => {
- expandedRows.value = products.value.filter((p) => p.id);
+ expandedRows.value = products.value.reduce((acc, p) => (acc[p.id] = true) && acc, {});
};
const collapseAll = () => {
expandedRows.value = null;
@@ -437,7 +437,7 @@ const getOrderSeverity = (order) => {
this.$toast.add({ severity: 'success', summary: 'Product Collapsed', detail: event.data.name, life: 3000 });
},
expandAll() {
- this.expandedRows = this.products.filter((p) => p.id);
+ this.expandedRows = this.products.reduce((acc, p) => (acc[p.id] = true) && acc, {});
},
collapseAll() {
this.expandedRows = null;