Author Topic: Option for [Enter] key to trigger filter on column text filters  (Read 159 times)

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Option for [Enter] key to trigger filter on column text filters
« on: September 20, 2024, 03:51:36 pm »
Most other grids have it, when typing the filter in the header column, pqGrid only works with a timeout which then triggers the filter to start.  Most other grids also have an option to also trigger the filter when the enter key pressed and also to disable the automatic timeout.

Please add an option for enabling [Enter] to trigger the filter and another option to disable the timeout filter.



ALSO, please could you allow the columnModel.filter to also be a function that returns the filter object, so instead of having to set the filter for multiple columns like this:

Code: [Select]
filter:{crules:[{condition:"contain"}], style:"text-align:left", listener:myListener, ....}
I could just do:

Code: [Select]
filter: myStandardFilter()
« Last Edit: September 20, 2024, 04:45:45 pm by jplevene »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6307
    • View Profile
Re: Option for [Enter] key to trigger filter on column text filters
« Reply #1 on: October 07, 2024, 04:10:39 pm »
pqgrid already provides various inbuilt filter listener options and custom listeners.

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Re: Option for [Enter] key to trigger filter on column text filters
« Reply #2 on: October 29, 2024, 11:13:04 pm »
The listeners work (I have made them work), and I have done them, but an option would be easier and would 100% work on new versions.

I also had to write the code below to prevent from doing 2 remote calls for the same filter, the second being triggered by the timeout:

Code: [Select]
var rule = { condition: ui.column.filter.crules[0].condition,  dataIndx: ui.column.dataIndx, value: ui.value, value2: ui.value2 },
CM = this.grid.pqGrid("getColModel");

// Check if the filter is not already applied
for(var i=0, len = CM.length; i < len; i++){
// If there is no change
if( CM[i]["dataIndx"]===ui.column.dataIndx && ui.value===CM[i]["filter"]["crules"][0]["value"] && ui.value2===CM[i]["filter"]["crules"][0]["value2"] )
rule = null;
}

// If we have a rule, apply it
if(rule)
this.grid.pqGrid("filter", {
oper: "add",
rules: [
rule
]
});

The issue is that with new versions, the above might end up not being compatible.

Also you promised to add the "X" in the column input filter to clear the text.  When you do this, my code might end up being incompatible.