fix(grid_row): sort options based on selected data first, so as to maintain order

Signed-off-by: Akhil Narang <me@akhilnarang.dev>
This commit is contained in:
Akhil Narang 2024-01-29 13:30:35 +05:30
parent 70a6a8334f
commit b2002e6aed
No known key found for this signature in database
GPG key ID: 9DCC61E211BF645F

View file

@ -461,6 +461,7 @@ export default class GridRow {
fieldname: "fields",
options: docfields,
columns: 2,
sort_options: false,
},
],
});
@ -495,12 +496,31 @@ export default class GridRow {
const show_field = (f) => always_allow.includes(f) || !blocked_fields.includes(f);
// First, add selected fields
selected_fields.forEach((selectedField) => {
const selectedColumn = this.docfields.find(
(column) => column.fieldname === selectedField
);
if (selectedColumn && !selectedColumn.hidden && show_field(selectedColumn.fieldtype)) {
fields.push({
label: selectedColumn.label,
value: selectedColumn.fieldname,
checked: true,
});
}
});
// Then, add the rest of the fields
this.docfields.forEach((column) => {
if (!column.hidden && show_field(column.fieldtype)) {
if (
!selected_fields.includes(column.fieldname) &&
!column.hidden &&
show_field(column.fieldtype)
) {
fields.push({
label: column.label,
value: column.fieldname,
checked: selected_fields ? selected_fields.includes(column.fieldname) : false,
checked: false,
});
}
});