Author Topic: Custom filter  (Read 4280 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Custom filter
« on: May 25, 2020, 07:37:43 pm »
I would like to apply a global filter and have that setting saved along with state data.
Would that be possible?

Ex. User selects 'a' from dropdown which applies
Code: [Select]
WHERE b = 1 to the select from DB.

Using PHP.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #1 on: May 26, 2020, 10:11:19 am »
[ Only Pro members may read this post. ]

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #2 on: May 26, 2020, 01:23:17 pm »
Ok, thanks.
How can I add the condition to the filterQuery request to DB in a effective way (PHP)?

if ( isset($_POST["custom_param"]))
{
    $pq_custom_params = $_POST["custom_param"];
...
}

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #3 on: May 26, 2020, 08:08:28 pm »
[ Only Pro members may read this post. ]

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #4 on: May 27, 2020, 03:10:38 pm »
Thank you.

Trying to add the custom value to save state but can't get it to work. Made a JSFiddle:

https://jsfiddle.net/queensgambit9/n2035zLo/13/

Would like the custom filter to be saved along with state.   

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #5 on: May 27, 2020, 09:20:15 pm »
[ Only Pro members may read this post. ]
« Last Edit: May 27, 2020, 09:32:38 pm by paramvir »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #6 on: May 28, 2020, 02:31:51 pm »
Sorry. I pick up the key value and add it to state, but not sure how to proceed:

Code: [Select]
var $toolbar = this.toolbar()
key = $toolbar.find(".filter100").attr('class')
value = $toolbar.find(".filter100").val()

state.key = value

Modified jsfiddle:
https://jsfiddle.net/queensgambit9/n2035zLo/17/
« Last Edit: May 28, 2020, 02:34:25 pm by queensgambit9 »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #7 on: May 28, 2020, 03:05:08 pm »
Got it working by:

Code: [Select]
var state = this.saveState({ stringify: false });

var $toolbar = this.toolbar()
key = $toolbar.find(".filter100").attr('class')
value = $toolbar.find(".filter100").val()

state.key = value
state = JSON.stringify( state )

Thanks.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #8 on: May 28, 2020, 03:56:36 pm »
[ Only Pro members may read this post. ]

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #9 on: May 28, 2020, 05:50:17 pm »
Thanks.

Loading issue:
The custom values does not seem to be sent when state is loaded even though they are set in state...?
How do I send the custom values to php file?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #10 on: May 28, 2020, 06:55:18 pm »
[ Only Pro members may read this post. ]

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #11 on: May 28, 2020, 07:43:53 pm »
No, it is saved in localStorage. The state contain the custom data but it ain't sent to php on:

this.loadState({ state: state })

...do I need to modify postData somehow?
Other grid state info works fine.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #12 on: May 28, 2020, 08:17:03 pm »
[ Only Pro members may read this post. ]
« Last Edit: May 28, 2020, 08:33:27 pm by paramvir »

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 315
    • View Profile
Re: Custom filter
« Reply #13 on: May 29, 2020, 01:00:34 pm »
Hmm...not sure I understand what you mean. I'll try clarify a bit what I would like to have:

In addition to the standard filters, I would like to have a global filter possibility, ex:

User select some column filters and choose to apply global filter from custom dropdown value 'only team 1 in country b'. In PHP file I check this value and generate SQL for it (added to filterQuery).
That setting should be saved with the state so that the user do not have to select it manually again when loading their state and want to perform same search.

Does it make sense or is there a better way of this?


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 5495
    • View Profile
Re: Custom filter
« Reply #14 on: May 29, 2020, 02:02:32 pm »
[ Only Pro members may read this post. ]