Dynamically replacing of grid

QuestionsDynamically replacing of grid
Kamran asked 3 months ago

Does innerHTML work for phpgrid?

In index.php, I create 2 grids.
<?php
include(“../lib/inc/jqgrid_dist.php”);
include_once(“config/config.php”);

$db_conf = array(
“type” => PHPGRID_DBTYPE,
“server” => PHPGRID_DBHOST,
“user” => PHPGRID_DBUSER,
“password” => PHPGRID_DBPASS,
“database” => PHPGRID_DBNAME
);

$grid = new jqgrid($db_conf);
$opt[“caption”] = “Article”;
$opt[“width”] = 1600;
$grid->set_options($opt);
$grid->table = “Article”;
$out_0 = $grid->render(“list1”);

// second grid
$grid = new jqgrid($db_conf);
$opt[“caption”] = “Country”; // caption of grid
$opt[“width”] = 1600;
$grid->set_options($opt);
$grid->table = “Country”;
$out_1 = $grid->render(“list2”);
?>

In the <body>, they are displayed in 2 tabs.
<div id=”gridtabs”>
<ul>
<li><a class=”tabitems” id=”item0″ href=”#tabs-0″>Grid0</a></li>
<li><a class=”tabitems” id=”item1″ href=”#tabs-1″>Grid1</a></li>
</ul>

<div id=”tabs-0″>
<div id=”out_report_0″>
<?php echo $out_0; ?>
</div>
</div>

<div id=”tabs-1″>
<div id=”out_report_1″>
<?php echo $out_1; ?>
</div>
</div>
</div>

An event calls a JavaScript function, which, via Ajax, is sent to a PHP function.
function createReport() {
global $db_conf;

$grid = new jqgrid($db_conf);
$opt[“caption”] = “Customers”;
$opt[“width”] = 600;
$grid->set_options($opt);
$grid->table = “Customers”;
$report = $grid->render(“list3”);

return $report;
}

The returned $report in onDone(s):
function onDone(s)
{
document.getElementById(“out_report_0”).innerHTML = s;
}

The grid $out_0 disappears on tabs-0, and …nothing appears!

Tried not creating a new grid but copying $out_1 from tabs-1 to tabs-0.
Again, nothing…

In createReport(), changed return $report; to:
ob_start();
echo $report;
$reportHTML = ob_get_clean();
return $reportHTML;

Again, nothing…

What am I doing wrong?

Thank you for any advice!

2 Answers
Abu Ghufran Staff answered 3 months ago

Hello,

I’ve tested loading grid via ajax in a div using jquery.

Refer this code:

https://gist.github.com/gridphp/c85ee8db525ae46de40b118718fca241#file-master-detail-ajax-php-L38

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Kamran answered 3 months ago

Thank you so much! Overall, it worked!
There are still some details specific to my project. First, I’ll try to figure them out on my own.

Kamran

Your Answer

13 + 5 =

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?