Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Ben C on Mar 05, 2009 11:17
open dhtmlx forum
grid undefined in loadXML with callback function

How do I reference the grid in the callback function? The way that I'm doing it seems to be undefined. I've tried both "this" and "myGrid" See below:

function doInitLayout(){
    var dhxLayout = new dhtmlXLayoutObject("layoutDiv", "2E");
    dhxLayout.cells("b").hideHeader();
    dhxLayout.cells("a").setHeight(100);
    dhxLayout.cells("a").fixSize(true,true);
    dhxLayout.cells("a").setText("Basic Search");
    dhxLayout.cells("a").attachObject("BasicSearchDiv");
    dhxLayout.setEffect("collapse", true);
    var myGrid = dhxLayout.cells("b").attachGrid();
    myGrid.setImagePath("${PathToDhtmlx}imgs/");
    myGrid.setSkin("light");
    myGrid.enableSmartRendering(true);
    myGrid.preventIECaching(true);
    myGrid.enableEditEvents(true,false,true);
    gridQString = "/indexXml"; //save query string to global variable (see step 5 for details)
    myGrid.loadXML(gridQString,onInitAddlSettings);
}
function onInitAddlSettings(){
    myGrid.hdr.rows[2].onclick=function(e){ // myGrid or "this" undefined <-----------------------------------------------------------*
     (e||event).cancelBubble=true; // block click event for second header row
    }
}


Just fyi, "/indexXml" returns an xml file that attaches a second header row to filter the grid. I want sorting on this row to be disabled.

I want to do it this way instead of "myGrid.loadXML(gridQString,function()=...);" so I don't have to replicate the code every time I call loadXML.


Also, is there a more detailed function API than this: \dhtmlx\dhtmlxGrid\doc\alpha.html? It leaves a bit to be desired. For instance, in attachHeader it gives no detail about what "values" can be. Is it a list of things? A string? And where does it say in the API that I can supply things like #master_checkbox or #combo_filter as a "value." I'd like this in one place without having to grep through the guide documentation.
Answer posted by Support on Mar 06, 2009 02:48
callback function used in loadXML doesn't provide direct reference to master object ( you may use onXLE event , for which "this" will be a grid object ) 
In case of existing code you can change 
  var myGrid = dhxLayout.cells("b").attachGrid();
to 
  myGrid = dhxLayout.cells("b").attachGrid();


or change 
  myGrid.loadXML(gridQString,onInitAddlSettings);
to the 
  myGrid.loadXML(gridQString, function (){ 
      myGrid.hdr.rows[2].onclick=function(e){
          (e||event).cancelBubble=true; // block click event for second header row 
     } 
 });

Answer posted by Ben C on Mar 06, 2009 07:30
And to the second part of my question?
Answer posted by dhxSupport on Mar 06, 2009 09:09