change grid table

Questionschange grid table
Adrian asked 2 years ago

Hi,

If I use something like this

If($_GET[“query1”] == “something…”) … I could change $->select = ….

I try to change $g->table in same mode, but it seems don’t work

It’s possible do I change table ($g->table) for insert/update/delete (the new table are same fields) in some condition?

Thank’s a lot

4 Answers
Abu Ghufran Staff answered 2 years ago

It should work as well. Infact we have done similar thing in ‘db table grid’ demo but it uses POST and SESSION variables.

Code: https://www.gridphp.com/demo/demos/apps/db-table-grid.phps
Demo: https://www.gridphp.com/demo/demos/apps/db-table-grid.php

I can suggest better If you share the related grid code.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Adrian answered 2 years ago

Hi,

Thank you for response, but in my case not working (not reload entire page)

In my code I have:

if (isset($_GET[“query2”]) && $_GET[“query2”] == 1) {
$g->select_command = “SELECT * FROM arhiva”;
$g->table = “arhiva”;
} else {
$g->select_command = “SELECT * FROM tabela”;
$g->table = “tabela”;
}

and I create a checkbox like this:

$(window).load(function() {

jQuery(‘#list1_pager_left .navtable tr’).append(‘<td><div style=”padding-left: 15px; padding-top:0px; float:left; color:darkblue; font-size: 150%”><label title=”arhiva”><input class=”arhiva” type=”checkbox” title=”Arhiva”/> Arhiva </label> </div> </td>’);

jQuery(“.arhiva”).click(function(){
var type = ($(this)[0].checked)?1:0;
grid = jQuery(“#list1”);
grid[0].p.search = false;
jQuery.extend(grid[0].p.postData,{‘query2′:type});
$(“select[id^=’gs_’]”).val(”);
$(“input[id^=’gs_’]”).val(”);
grid.trigger(“reloadGrid”,[{page:1}]);
});

}

 

The grid display correctly (“SELECT * FROM arhiva” if the checkbox is checked and “SELECT * FROM tabela” if not), but $g->table is always “tabela”

Please help!

Best regards

 

Abu Ghufran Staff answered 2 years ago

If both tables have same columns then,

The ajax call (postData) is sent via $_POST and you are checking $_GET. The ajax call looks irrelevant.

Second, if you perform add/update/del operation, this query2 variable is not passed in POST. If it’s part of url (that is $_GET) then you can use it in condition.

If you want to use it with POST data, You need to preserve the query2 is SESSION and put condition based on SESSION variable (not on GET or POST).

if (isset($_GET["query2"]))
$_SESSION["query2"] = $_GET["query2"];

if (isset($_SESSION["query2"]) && $_SESSION["query2"] == 1) {
$g->select_command = "SELECT * FROM arhiva";
$g->table = "arhiva";
} else {
$g->select_command = "SELECT * FROM tabela";
$g->table = "tabela";
}

If it still does not work, Please share complete grid file.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Adrian answered 2 years ago

Thank you very much!

It’s working!

Best regards,

Your Answer

9 + 3 =

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?