Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Nath Papadacis on Aug 06, 2007 15:04
open dhtmlx forum
Multiple dhtmlxGrids with setOnEditCellHandler problem. Only last initialised grid will work.

Hi,

First of all what I'm using:
xajax
php
dhtmlxGrid - Free edition
IIS 7
IE 7
Vista

I'm trying to return the results from a query into several grids (one for each user). This is done using the addRow function. If the returned result is for the current logged on user I want to add additional functionality to the grid to allow editing (I'm using the setOnEditCellHandler). If the logged on user has their grid initialised last then there is no problem but if it is created before any others then the handler function fails to fire.

Here's some code to help explain.

if ($name == $user) {        // If the result from query is for the current logged on user
    $objResponse->script($name."grid = new dhtmlXGridObject('".$name."notes');");
    $objResponse->script($name."grid.setImagePath('grid/imgs/');");
    $objResponse->script($name."grid.setHeader('Notes,img:[grid/imgs/delete.gif]');");
    $objResponse->script($name."grid.setInitWidths('160,20');");
//$objResponse->script($name."grid.enableAutoHeight(true,100);");
    $objResponse->script($name."grid.setColAlign('left,center');");
    $objResponse->script($name."grid.setColTypes('ed,ed');");
    $objResponse->script($name."grid.setColSorting('str');");
    $objResponse->script($name."grid.setOnEditCellHandler(NotesControl);");
    $objResponse->script($name."grid.enableAlterCss('even','uneven');");
    $objResponse->script($name."grid.enableMultiline(true);");
    $objResponse->script($name."grid.enableKeyboardSupport(false);");
    $objResponse->script($name."grid.init();");
} else {
// We don't want people editing other comments.
    $objResponse->script($name."grid = new dhtmlXGridObject('".$name."notes');");
    $objResponse->script($name."grid.setImagePath('grid/imgs/');");
    $objResponse->script($name."grid.setHeader('Notes');");
    $objResponse->script($name."grid.setInitWidths('180');");
//$objResponse->script($name."grid.enableAutoHeight(true,100);");
    $objResponse->script($name."grid.setColAlign('left');");
    $objResponse->script($name."grid.setColTypes('ro');");
    $objResponse->script($name."grid.setColSorting('str');");
    $objResponse->script($name."grid.enableAlterCss('even','uneven');");
    $objResponse->script($name."grid.enableMultiline(true);");
    $objResponse->script($name."grid.enableKeyboardSupport(false);");
    $objResponse->script($name."grid.init();");
}

//This happens once for each user. Followed by the following
if ($name == $user) {
    $objResponse->script($name."grid.addRow($j,'".urldecode(odbc_result($rs2,1)).",X',$j);");
} else {
    $objResponse->script($name."grid.addRow($j,'".urldecode(odbc_result($rs2,1))."',$j);");
}

The Div tags are created dynamically on each iteration before the above code using the variable $name as a prefix
e.g. <div id="bobnotes"></div>
then I reference the gridobject using $name again e.g. bobgrid = new dhtmlxGridObject("bobnotes");

Anyway the responses come back fine and it creates the grids perfectly but you can see from above the first 'if' sets bobgrid.setOnEditCellHandler(NotesControl);

If bob's grid is drawn last then it works fine but if on a subsequent iteration another grid is drawn then the NoteControl handler doesn't fire.

I suppose things to bear in mind is that all this is handled by xajax and so the resulting javascript code is dynamically created. I don't know if this has an impact.

Hope someone can shed some light on it.
Answer posted by Inga (Support) on Dec 10, 2014 16:03

Not much can be said in addition to the reply above, but you also can check ext js and open source scheduling calendar and find out what we have probably missed in our explanation.