Author Topic: Set initial filters once as default before remote load  (Read 384 times)

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 141
    • View Profile
Set initial filters once as default before remote load
« on: January 23, 2025, 02:13:59 am »
I have a grid with dataModel.location="remote"

Just on the first load (one off when data loaded for the first time only) I want to set an initial filter on a column.  So when refresh, add/remove filters, etc. it must NOT revert to the initial filter option.

I want to avoid calling the remote server twice.

After building the table, I have tried making the dataModel.location="local", applying the filter then dataModel.location="remote" which works, but is there a cleaner way to set the initial filter in "options"?

I have tried using grid.one like below, however this calls the remote server to load the data twice, being one time to load the initial data (unfiltered) then again after the "one" is called with a new filter.

Code: [Select]
grid.one("load", function (evt, ui) {
// Apply initial filtering.
grid.filter({
oper: "add",
rules: [
{ dataIndx: "DEPOT", value: ["London"] },
]
});
});
« Last Edit: January 23, 2025, 02:56:55 am by jplevene »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6353
    • View Profile
Re: Set initial filters once as default before remote load
« Reply #1 on: January 23, 2025, 10:36:19 pm »
There is no need to use load event to apply initial filtering.

The initial filter options can be set just by adding column.filter option. It works same for local and remote filtering.

Code: [Select]
{ title: "Customer Name", width: 120, dataIndx: "ContactName",
                filter: {
                    crules: [{condition: 'begin', value: 'M' }]                   
                }
            },

Remote server is called only once as the filtered data is loaded initially.

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 141
    • View Profile
Re: Set initial filters once as default before remote load
« Reply #2 on: January 24, 2025, 12:32:48 am »
Thanks. Can't believe I missed that.