Author Topic: Listener bug in v10.1.0  (Read 25 times)

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Listener bug in v10.1.0
« on: November 19, 2024, 11:59:46 pm »
I had a listener that previously worked.  The idea of the listener is that the filter starts either when the [ENTER] key is pressed or the timeout happens. v10.0.0 and below worked fine, v10.0.1 now has an issue, in that every keypress, the filter starts due to the timeout.

If I comment out the "timeout", it works fine except the timeout is never triggered.  If I include the timeout, it goes all wrong.

Ideally I would like to avoid using the "do_filter" function and just use the default filter start trigger, but I don't know how to call that.

Code: [Select]
var text_listener = {
"keydown": function(e, ui)
{
if(e.key==="Enter")
do_filter(ui);
},
// If I comment out below for v10.0.1 there are no wrong filter triggers
"timeout": function(e, ui){
do_filter(ui);
}
};

function do_filter(ui)
{
var rule = { condition: ui.column.filter.crules[0].condition,  dataIndx: ui.column.dataIndx, value: ui.value, value2: ui.value2 },
CM = $("#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)
$("#grid").pqGrid("filter", {
oper: "add",
rules: [
rule
]
});
}

...

columnModel = [
{dataIndx:"NAME", title:"NAME", filter:{crules:[{condition:"contain"}], style:"text-align:"+dir, listener:text_listener}},
...
];

Doing a console log I found the bug.  The timeout in the listener is getting the "keydown" event and not getting the "timeout" event.   I commented out the "keydown" listener and timeout worked.

I tried below, but either keydown or timeout get missed:

Code: [Select]
var text_listener = {
"keydown": function(e, ui)
{
if(e.type==="keydown" && e.key==="Enter")
do_filter(ui);
},
// If I comment out below for v10.0.1 there are no wrong filter triggers
"timeout": function(e, ui){
if(e.type==="timeout")
do_filter(ui);
}
};

I shouldn't have to test for the event as that function should never be called for a different event.
« Last Edit: November 20, 2024, 01:18:48 am by jplevene »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6307
    • View Profile
Re: Listener bug in v10.1.0
« Reply #1 on: November 20, 2024, 11:45:22 am »
I understand that your goal is to trigger filter on a certain timeout ( time lapse ). And if user press enter key before that time lapse, filtering should be triggered immediately and pending filter due to timeout shouldn't be triggered after that.

Default filter listener in v10.1.0 does that.

Please read the column.filter documentation for more details: https://paramquery.com/pro/api#option-column-filter

Please remove your custom code to get rid of the issues faced by you.

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Re: Listener bug in v10.1.0
« Reply #2 on: November 20, 2024, 03:58:22 pm »
Thanks for adding this, I have removed all of the code.

However I feel it is my duty to still report there is still a bug there.  I added the listener code as this:

var listener = {
   "keydown": function(e, ui)
   {
      console.log("keydown", e);
   },
   "timeout": function(e, ui){
      console.log("timeout",e);
   }
};

When I typed the name "David" (no [Enter] key pressed) I got the attached result.  As you can see, timeout is getting called for keydown events, sometimes it is the other way round.

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Re: Listener bug in v10.1.0
« Reply #3 on: November 20, 2024, 07:36:09 pm »
Also just to mention, if I just set the "keydown" listener, the "timeout" normal course of things stops being triggered