Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Rainolf on Sep 13, 2009 13:33
open dhtmlx forum
Passing cell content to dataprocessor

Hi,
I'm creating 2 grid :

grid1 is populated with data from Mysql database with dataprocessor method.
grid2 should be populated with data when onRowSelect event comes from the first grid and should
load data from mysql database with data filtered by a value in the first grid.

see the code:

<script>
var mygrid;
mygrid = new dhtmlXGridObject('employee');
mygrid.setImagePath("includes/dhtmlxSuite/dhtmlxGrid/codebase/imgs/");
mygrid.setHeader("Matricola,Cognome,Nome,Filiale,Timbrature");
mygrid.attachHeader("#text_filter,#text_filter,#text_filter,#select_filter,#rspan");
mygrid.setInitWidths("133,150,150,150,160");
mygrid.setColAlign("left,left,left,left,center");
mygrid.setSkin("modern");
mygrid.setColSorting("str,str,str,str");
mygrid.setColTypes("ro,ro,ro,ro,link");
mygrid.attachEvent("onRowSelect",viewtimesheet);
mygrid.init();
mygrid.loadXML("includes/php/getdata.php");    //Data Processor

</script>
</div>

<div id="timesheet" style="width:757px;height:250px;"></div>
<br>
<input type="button" name="update" value="Aggiorna Dati" onclick="myDataProcessor.sendData();">
</div>
<script>
var mygrid2;
mygrid2 = new dhtmlXGridObject('timesheet');
mygrid2.setImagePath("includes/dhtmlxSuite/dhtmlxGrid/codebase/imgs/");
mygrid2.setHeader("Matricola,Cognome,Nome,Filiale,Timbrature");
mygrid2.attachHeader("#text_filter,#text_filter,#text_filter,#select_filter,#rspan");
mygrid2.setInitWidths("133,150,150,150,160");
mygrid2.setColAlign("left,left,left,left,center");
mygrid2.setSkin("modern");
mygrid2.setColSorting("str,str,str,str");
mygrid2.setColTypes("ro,ro,ro,ro,link");

mygrid2.init();
</script>

and the function is:

function viewtimesheet(rowID,celInd){
mygrid2.clearAll();//clear all rows if was loaded before
mygrid2.loadXML("includes/php/getdata1.php");    //Data Processor
}

the php server code is :

<?php
//include db connection settings
//change this setting according to your environment
require_once("config.php");

//include XML Header (as response will be in xml format)
header("Content-type: text/xml");
//encoding may be different in your case
echo('<?xml version="1.0" encoding="iso-8859-1"?>');
//start output of data
echo '<rows id="0">';

//output data from DB as XML
$sql = "SELECT hs.loc_code, hs.loc_city, b.employee_id, b.emp_lastname, b.emp_firstname, a.emp_number " .
        "FROM hs_hr_location hs " .
        "JOIN (hs_hr_emp_locations a " .
        "JOIN hs_hr_employee b " .
        "ON (a.emp_number=b.emp_number)) " .
        "ON (a.loc_code=hs.loc_code) " .
        "WHERE b.emp_status<>'EST009' AND b.emp_status<>'EST011' AND b.emp_status<>'EST012'";
$res = mysql_query ($sql);
    
if($res){
    while($row=mysql_fetch_array($res)){
        //create xml tag for grid's row
        echo ("<row id='".$row['emp_number']."'>");
        print("<cell><![CDATA[".$row['employee_id']."]]></cell>");
        print("<cell><![CDATA[".$row['emp_lastname']."]]></cell>");
        print("<cell><![CDATA[".$row['emp_firstname']."]]></cell>");
        print("<cell><![CDATA[".$row['loc_city']."]]></cell>");
        print("</row>");
    }
}else{
//error occurs
    echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in ".__FILE__." file<br>";
}
echo '</rows>';
?>

At the moment i'm not able to pass a particular cell value when the row which belong is selected...
how can i do that in order to insert the value/variable in the WHERE clause of select?
Thank You very much,,,,
Answer posted by Support on Sep 14, 2009 09:02
on client side

function viewtimesheet(rowID,celInd){ 
mygrid2.clearAll();//clear all rows if was loaded before
mygrid2.loadXML("includes/php/getdata1.php?filter="+mygrid.cells(rowID,celInd).getValue());   //send cell value to the server

on server side

  "WHERE b.emp_status<>'EST009' AND b.emp_status<>'EST011' AND b.emp_status<>'EST012'".
  " AND some_filed like '".$_GET["filter"]."'";
Answer posted by Rainolf on Sep 14, 2009 03:50
The code on server side seem to be not correct because my editor says syntax error:

i've replaced with:

"WHERE b.emp_status<>'EST009' AND b.emp_status<>'EST011' AND b.emp_status<>'EST012'AND b.emp_firstname like'".$_GET["filter"];

but page bad xml....

Why?
Answer posted by Support on Sep 14, 2009 09:03
Please try to add an extra whitespace after "like" instruction ( actually you can use any other filtering rule here ) 
<>'EST012'AND b.emp_firstname LIKE    '".$_GET["filter"]."' ";  //extra whitespace and closing quote