Can not Export

hi,
In my application, I’m creating runtime tabs and loading grids with following function, where each grid keeps data from different queries at the time of creation. I want to export each grid into excel, by clicking export button in tool bar attached to each tab. with below coding I’m getting " ‘mygrid’ is undefined" error for the line within the toolbar function, how to resolve this,
regards,
suminda,

tab creating function******
ncat.set_grid_table=function(win,text,recid){
var mygrid = win.attachGrid();
mygrid.selMultiRows = true;
mygrid.setSkin(“dhx_skyblue”);
mygrid.enableCSVAutoID(false);
mygrid.enableSmartRendering(true);
mygrid.setHeader(“Category,Value”);
mygrid.clearSelection();
mygrid.clearAll();
mygrid.init();
mygrid.xmlFileUrl = “./php/load.php?action=loadsingle&type=”+text+“&recid=”+recid+“etc=”+new Date().getTime();
mygrid.loadXML(mygrid.xmlFileUrl);
};


note:var ncat={}; //namespace
*******tool bar function
ncat.tab_toolbar_click=function(id){
switch(id){
case “export”:
mygrid.toExcel(“./grid-html-php/generate.php”);
break;
}
};


Hi,
mygrid in your case is not a global variable, so it doesn’t link to grid instance. You should use variable which references to grid instance instead of mygrid.

hi,
how to define mygrid as global, since it is attaching dynamically to a window passing to function,
can you pls provide any clue on code snippet.

regards,
suminda

You should save grid instance in some global variable (or property of global variable).
For example:

************tab creating function******************
ncat.set_grid_table=function(win,text,recid){
var mygrid = win.attachGrid();
mygrid.selMultiRows = true;
mygrid.setSkin("dhx_skyblue");
mygrid.enableCSVAutoID(false);
mygrid.enableSmartRendering(true);
mygrid.setHeader("Category,Value");	
mygrid.clearSelection();
mygrid.clearAll();
mygrid.init();
mygrid.xmlFileUrl = "./php/load.php?action=loadsingle&type="+text+"&recid="+recid+"etc="+new Date().getTime();
mygrid.loadXML(mygrid.xmlFileUrl);
ncat.grid = mygrid;
};


ncat.tab_toolbar_click=function(id){
switch(id){
case "export":
ncat.grid.toExcel("./grid-html-php/generate.php");
break;
}
};

hi,

it is working fine,

thanks,

regards,
suminda,