change query on the fly

Questionschange query on the fly
Glenn asked 9 years ago

Hi Abu,
I would like to change the grid's $ogrid->select_command sql on the fly.

I created a button on the toolbar that can refresh the grid, but need a way to change the sql before it is refreshed.
jQuery('#list1').trigger('reloadGrid',[{page:1}]);

Thanks Glenn

6 Answers
Abu Ghufran answered 9 years ago

Just to give an idea,

You can pass extra param e.g. 'sql' with some value e.g. 'query1' and put IF condition on select_command statements.
jQuery('#list1').setGridParam({ postData: { sql: 'query1' } }).trigger('reloadGrid');

There is a limitation that you cannot change the # of columns and other column settings with this. As reloadGrid is ajax call, only loading data will be affected.

Glenn answered 9 years ago

Thank Abu,

How would I access that param?
What would that if statement look like?

Thanks
Glenn

Abu Ghufran answered 9 years ago

it would be something like:

if ($_POST["sql"] == "query1")
$g->select_command = "…";

else if ($_POST["sql"] == "query2")
$g->select_command = "…";

Glenn answered 9 years ago

Thanks Abu,
I tried but could not seem to get it working.
I modified alternate-row with a button called ShowAll.
http://www.websalesdesign.com/proj/lib/phpgrid-full/index.php
http://www.websalesdesign.com/proj/lib/phpgrid-full/demos/appearence/alternate-row.php

What did I miss?

Thanks
Glenn

Abu Ghufran answered 9 years ago

I just checked it, the extra param is passed in $_GET not in $_POST.
So you need to change it to:

if ($_GET["sql"] !== "ALL")
$qry = $qry . " where name like '%posts'";

Glenn answered 9 years ago

Thank Abu,
It works perfectly now.
I should have spotted that typo.

Your Answer

20 + 10 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?