Get KoolPHP UI with 30% OFF!

Ajax Load KoolControl to Div Example

ADavid Wulkan
Has anyone been successful at modifying this example code to load a grid control yet? Could you please post your code here so I can see where I am going wrong.
OK, I got this working:
1. This is the example code with two changes. First, I added a function to run the PHP script file that builds the grid control. Second, I added a button the run the javascript function: "load_grid()"
tables2.php
<?php include "inc/header_inc.php"; ?>
<?php //include "inc/dbkool.php"; ?>
<?php include "inc/ajax.php"; ?>
<form id="form1" method="post">
<script type="text/javascript" src="<?php echo $KoolControlsFolder; ?>/KoolAjax/koolajax_extension.js"></script>
<style>
  #target {
    width:655px;
    border:dotted 1px gray;
    min-height:50px;
    padding:10px;
  }
</style>
		
<div id="target"></div>
<script type="text/javascript">
  function load_treeview() {
    koolajax.load("tree.php",handle_ondone);
  }
  function load_listbox() {
    koolajax.load("listbox.php",handle_ondone);
  }
  function load_grid() {
    //document.write('<div>Grid should be here</div>');
    koolajax.load("gridbasic.php",handle_ondone); 
  }
  function handle_ondone(result) {
    var _target = document.getElementById("target");
    _target.innerHTML = result;
    run_script_in_element("target");//This function is inside koolajax_extension.js
  }
</script>
<input type="button" value="Load TreeView" onclick="load_treeview()" />
<input type="button" value="Load ListBox" onclick="load_listbox()" />
<input type="button" value="Load Grid" onclick="load_grid()" />
</form>
</body></HTML>

2. This is the PHP file that builds the grid control. Whats important to know is
A. The Ajjax control should not be here.
B. This script needs to know how to get to the KoolPHP directories. (my file inc/gvars.php)
C. This script needs to be abe to access the database. (my file inc/dbkool.php)
gridbasic.php
<?php
require_once "inc/gvars.php";
include "inc/dbkool.php"; 
         require $KoolControlsFolder."/KoolGrid/koolgrid.php";
	 $lvl1Datasource = new MySQLDataSource($db_con); 
         $lvl1sql="select customerNumber,customerName,phone,city from customers";
	 $lvl1Datasource->SelectCommand = $lvl1sql;
	 $lvl2Datasource = new MySQLDataSource($db_con); 
         $lvl2sql="select orderNumber,orderDate,status,customerNumber from orders";
	 $lvl2Datasource->SelectCommand = $lvl2sql;
 
	 $lvl3Datasource = new MySQLDataSource($db_con); 
         $lvl3sql="select orderNumber,productName,quantityOrdered,priceEach from orderdetails,products where orderdetails.productCode=products.productCode";
	 $lvl3Datasource->SelectCommand = $lvl3sql;
	 $grid = new KoolGrid("grid");
	 $grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
	 $grid->styleFolder="default";
	 $grid->Width = "655px";
	 $grid->RowAlternative = true;
	 $grid->AjaxEnabled = true;
	 $grid->AjaxLoadingImage =  $KoolControlsFolder."/KoolAjax/loading/5.gif";
//LEVEL 3 TABLE
	 $lvl3Table = new GridTableView();
	 $lvl3Table->Width = "100%";
	 $lvl3Table->DataSource = $lvl3Datasource;
	 $lvl3Table->AddRelationField("orderNumber","orderNumber");
	 $lvl3Table->AutoGenerateColumns = true;//Auto Generate all column from tables
	 $lvl3Table->DisableAutoGenerateDataFields = "orderNumber";//Disable generate column for orderNumber data fields.
 
//LEVEL 2 TABLE
	 $lvl2Table = new GridTableView();
	 $lvl2Table->Width = "100%";	
	 $lvl2Table->DataSource =$lvl2Datasource;
	 $lvl2Table->AddRelationField("customerNumber","customerNumber");
	 $lvl2Table->AutoGenerateExpandColumn = true;
	 $lvl2Table->AutoGenerateColumns = true;
	 $lvl2Table->DisableAutoGenerateDataFields = "customerNumber";
	 $lvl2Table->AddDetailTable($lvl3Table);
	
//MASTER TABLE
	 $grid->MasterTable->DataSource = $lvl1Datasource;
	 $grid->MasterTable->AutoGenerateExpandColumn = true;
	 $grid->MasterTable->AutoGenerateColumns = true;
	 $grid->MasterTable->AddDetailTable($lvl2Table);
 
	 $grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
	 $grid->Process();
	//echo $koolajax->Render();
	echo $grid->Render();
?>

3. Ajax.php
<?php
	require_once $KoolControlsFolder."/KoolAjax/koolajax.php";
	$koolajax->scriptFolder = $KoolControlsFolder."/KoolAjax";
	echo $koolajax->Render();
?>

4. Just to remove curiosity This is my dbkool.php
<?php
$db_con = mysql_connect( '127.0.0.1', 'mywebuser', 'mywebpasswd', 'mykooldbname');
mysql_select_db('mykooldbname');
if (!$db_con) {
    die('Connect Error (' . mysql_connect_errno() . ') ' . mysql_connect_error());
}
?>

That's it. Now I am working on the (harder for me) update panel example; var request = new KoolAjaxRequest( {
Good luck
Posted Dec 26, 2015 , edited Jan 3, 2016 Kool -
Peter
The loading KoolControl via ajax is possible with KoolAjax UpdatePanel. Here is the example .
Posted Dec 27, 2015 Kool
ADavid Wulkan
Peter, the one time I got the grid to appear in the update panel (and I have not been able to replicate that) the grid was non-responsive to any clicks. I suspect there is something I am not understanding about the ajax for the update panel and the ajax for the grid control itself?
Posted Feb 3, 2016 Kool
Christian
Hi!
I got this working too.

But when i click on the prev, next ... link in the grid, the result Looks like this

<!DOCTYPE html>
<head>
</head>
<body>
<?php 
//include '../pages/am.header.php';
//include '../pages/am.auth.php';
require_once '../class/am.database.class.php';
require_once '../class/am.kool.include.php';
	$KoolControlsFolder = "../class/KoolPHPSuite/KoolControls";
	require $KoolControlsFolder."/KoolAjax/koolajax.php";
	$koolajax->scriptFolder = $KoolControlsFolder."/KoolAjax";
	
	if(isset($_POST["load"]))
	{
		require $KoolControlsFolder."/KoolGrid/koolgrid.php";
		
		$db = Datenbank::factory();
		$ds_master = new SQLSRVDataSource($db->GetConnection());
		
		$ds_master->SelectCommand = $db->QueryLoadFromFile('test_sql.sql');
		
		$grid = new KoolGrid("VendorGridSubstance");
		$grid->CharSet = "UTF-8";
		$grid->scriptFolder = $KoolControlsFolder."/KoolGrid";
		//@$grid->Localization->Load($KoolControlsFolder."/KoolGrid/localization/de.xml");
				
		$grid->styleFolder="default";
		$grid->Width = "937px";
		//$grid->Height = "600px";
		$grid->PageSize  = 50;
		$grid->RowAlternative = true;
		$grid->AjaxEnabled = true;
		
		$grid->MasterTable->PageSize  = 25;
		$grid->MasterTable->Pager = new GridPrevNextPager();// GridPrevNextPager is inherited from GridPager.
		$grid->MasterTable->Pager->ShowPageSize = true;
		$grid->MasterTable->Pager->PageSizeOptions = "25,50,100";		
		$grid->MasterTable->DataSource = $ds_master;
		$grid->MasterTable->AutoGenerateExpandColumn = false;
		$grid->MasterTable->AutoGenerateColumns = true;
		//$grid->MasterTable->AddDetailTable($table_order);
		$grid->MasterTable->Pager = new GridPrevNextAndNumericPager();
		$grid->Process();
	}
?>
<form id="form1" method="post">
<?php echo $koolajax->Render();?>	 	
				<?php echo KoolScripting::Start();?>
					
					<updatepanel id="mypanel">
						<content>
 
								<?php
									if(isset($_POST["load"])){
										echo $grid->Render();
									}
								?>
 						</content>
						<loading image="<?php echo $KoolControlsFolder ?>/KoolAjax/loading/5.gif" />
					</updatepanel>
				<?php echo KoolScripting::End();?>	
 
 
		<script type="text/javascript">
			function load_grid()
			{
				mypanel.attachData("load","done");
				mypanel.update();	
			}						
		</script>
 
		<input type="button" value="Load Grid" onclick="load_grid()" /> 
</form>
</body>
Posted Oct 24, 2016 , edited Oct 24, 2016 Kool
ADavid Wulkan
In other words, you couldn't get it to work either.
Posted Oct 25, 2016 Kool
Anthony Amolochitis
Why don't you just use the grid's built in ajax functionality? It works perfectly.
What is the reason for trying to use an update panel to create an ajaxed koolgrid when the koolgrid has it built into it? I'm just curious.
Posted Oct 25, 2016 Kool
Christian
The reason is simple. I want to load the grid after the whole page is loaded because it takes about 20 seconds. I thought the update panel would be a good solution
Posted Oct 26, 2016 Kool
Anthony Amolochitis
1. Just build an empty grid.
2. On grid load javascript event, attach a parameter to the grid to tell the server to pull the query you are trying to execute.
Then call the grid commit and reload javascript method. This will post back the attached parameter to the grid.
3. Your are done.
Just make sure your grid has the correct ajax url set.
Posted Oct 26, 2016 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool
Raj
Thank you ADavid Wulkan
Now I am able to do project on PHP by my own
Posted Dec 14, 2017 Kool