ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: queensgambit9 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 WHERE b = 1
to the select from DB.
Using PHP.
-
Any custom data can be appended to state data as below:
var state = grid.saveState({ stringify: false });
state.b = 1; //custom data.
state = JSON.stringify( state );
-
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"];
...
}
-
it can be appended to the $filterQuery returned by FilterHelper class.
Conceptually ( pseudo code ):
$fiterQuery = $fiterQuery . " AND " . $custom_field_name . " = ". $custom_field_value
-
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.
-
I don't see any attempt to add custom value to save state in your jsfiddle. Can you please clarify and highlight the relevant code.
-
Sorry. I pick up the key value and add it to state, but not sure how to proceed:
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/
-
Got it working by:
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.
-
Good to know that you got it working.
Just a small correction that you might need while key value assignment.
state[ key ] = value
-
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?
-
I presume that you are saving grid state remotely in db which is done with an $.ajax call.
So any custom data which is added to the state would also be sent automatically along with main state data.
-
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.
-
No, it is saved in localStorage.
Then your mentioned requirement does not make sense. Why do you want to combine custom data with grid state?
-
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?
-
Thanks for the clarification.
1. Entire grid state is not saved in local storage when stringify: false is passed. It has to be saved manually with
localStorage.setItem( name, state);
2. Please use dataModel.postData callback to send custom data from grid to remote script.