Author Topic: column filter for id/text select list shows the id rather than the text  (Read 7506 times)

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 167
    • View Profile
When I use the "Range" option in the column filter, it's showing me the IDs (9,3,1,0) instead of the text. How to show the text (Division, Business Unit...)

                        editor: {
                            type: "select",
                            options: [{ "9": "Division" }, { "3": "Business Unit" }, { "1": "Portfolio" }, { "0": "Other" }],
                        },
                        render: function (ui) {
                            var option = ui.column.editor.options.find(function (obj) {
                                return (obj[ui.cellData] != null);
                            });
                            return option ? option[ui.cellData] : "";
                        }

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6557
    • View Profile
Please copy the column render and editor options to the grid column in filter popup.

Code: [Select]
            filter: {
                crules: [{condition: 'range'}],
                selectGridObj: function (ui) {
                    //reuse column renderer and editor options in filter popup.
                    var col = ui.obj.colModel[0];
                    col.renderLabel = ui.column.render;
                    col.editor = ui.column.editor;
                    col.editable = false;
                }
            },



As a side note, an issue has been found in filter popup whose fix is mentioned in the following post:

column filter popup options are not refreshed after grid data is changed

https://paramquery.com/forum/index.php?topic=4726.msg17299#msg17299
« Last Edit: June 20, 2024, 01:10:28 pm by paramvir »

Syouji Matsumoto

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
For a column that stores IDs in the data and displays labels via a select editor (valueIndx / labelIndx) and render, header filtering works on the raw cell values (IDs), not the displayed labels. This is expected since filters compare raw data, but it's confusing for end users. Here is a complete setup for pqGrid Pro v10 that makes the whole filtering UX label-based, without changing the underlying data model (cells keep storing IDs).

Three parts are needed:

1. Show labels in the range/equal checklist popup — copy the column's render and editor into the popup grid column via selectGridObj (this part is documented in the demos):


filter: {
    crules: [{ condition: 'range' }],
    selectGridObj: function (ui) {
        var col = ui.obj.colModel[0];
        col.renderLabel = ui.column.render;
        col.editor = ui.column.editor;
        col.editable = false;
    }
}
2. Make text conditions (contain, begin, end, …) compare against labels — override compare of those conditions via filter.conditions, translating the cell's ID to its label before comparing. Note that pqGrid passes the filter input normalized (trimmed + uppercased) for string columns, so normalize the label the same way:


function labelCompare(fn) {
    return {
        compare: function (cellData, value, value2, rowData, column) {
            var raw = rowData ? rowData[column.dataIndx] : cellData;
            var label = (idToLabelMap[String(raw)] || '').trim().toUpperCase();
            return fn(label, value, value2);
        }
    };
}

filter.conditions = {
    contain: labelCompare(function (a, b) { return a.indexOf(b) !== -1; }),
    begin:   labelCompare(function (a, b) { return a.indexOf(b) === 0; }),
    end:     labelCompare(function (a, b) { return a.endsWith(b); })
    // ...same pattern for notcontain, notbegin, notend, less, great, lte, gte, between, regexp
};
Important: do not override range, equal and notequal. Their input UI is the checklist whose checked values are the raw IDs, so the default ID comparison is the correct one there (the display is already handled by step 1). empty / notempty also work unchanged.

3. The search box inside the filter popup — this was the non-obvious part for us. The popup is a separate internal pqGrid whose rows also hold raw IDs (renderLabel only affects display), and its search box is a contain filter on that internal grid. So typing a label there finds nothing. Fix: apply the same condition overrides to the popup grid's column, inside the same selectGridObj callback:


selectGridObj: function (ui) {
    var col = ui.obj.colModel[0];
    col.renderLabel = ui.column.render;
    col.editor = ui.column.editor;
    col.editable = false;
    // make the popup's search box label-based too
    col.filter = col.filter || {};
    col.filter.conditions = ui.column.filter.conditions;
}
With these three pieces, the checklist shows labels, free-text conditions match against labels (case-insensitive, same as regular text columns), and the popup's search box filters the checklist by label — while the actual filtering rules still operate on the ID values internally.

Optionally, add a label-based column.sortType as well, since sorting has the same raw-value behavior.