How to attach an event handler to a grid after all records h

Hello,



Does any one know how can I attach an event handler or capture ‘finish loading’ moment somehow ?

I have a grid loaded from XML:



if (bReload)

mygrid.clearAndLoad(strUrl, OnGridLoaded)

else

mygrid.load(strUrl, OnGridLoaded);



// if we load the grid having a single row show it’s details automatically

function OnGridLoaded()

{

if (mygrid.getRowsNum() == 1)

{

var lnk = window.document.getElementById(“lnkSelectRow0”);

if (lnk != null) lnk.click();

}

}



Grid has paging turned on, and XML gets returned from server side (aspx) by pages.

What I want is to auto-click a link in the first cell After all records had been loaded.

Problem is OnGridLoaded() doesn’t really work. This is because (I explored it using IE8’s debugger)

data are not loaded at the time grid calls this function (even if it is called OnGridLoaded by someone!)

So when I try to get this link it doesn’t exist yet.



How can I get my link so I can click it then ?



Thanks,



Vlad



What I want is to auto-click a link in the first cell After all records had been loaded.
Unfortunately it’s not clear which link do you want to click. Do you want to open first cell’s editor when rows are loaded?
>>Problem is OnGridLoaded() doesn’t really work.
Unfortunately we cannot reproduce this issue locally.
To check if rows were loaded you can use “onXLE” event. Please find more information here dhtmlx.com/dhxdocs/doku.php?id=d … vent_onxle


>> Unfortunately it’s not clear which link do you want to click. Do you want to open first cell’s editor when rows are loaded? 



I have grid and detail tabs beneath it. When user clicks an image on the row (a link with an image in the first cell) it populates detail tabs.



Now if it happens that the grid has only a single row, I need to make detail tabs to be populated automatically.



mygrid.clearAndLoad(strUrl, OnGridLoaded)



I do it in OnGridLoaded function.



// if we load a grid having a single row - show it’s details automatically



function OnGridLoaded()



{



if (mygrid.getRowsNum() == 1)



{



var lnk = window.document.getElementById(“lnkSelectRow0”);



if (lnk != null)



{



var attr = lnk.getAttribute(“onclick”);



typeof attr == ‘function’ ? attr() : eval(attr);



}



else



window.setTimeout(OnGridLoaded, 100); // wait till the link is loaded



}



}



This function has setTimeout now. It waits for the grid to finish loading (probably in background?). If I remove this setTimeout call lnk variable will be equal to null! I fixed it but it took me a day to figure out what was happening.



Also: Lots of function do not work reliably, I can state it as a first time user for your grid. For example I was trying too configure grid with XML, columns, (btw add this on load event handler there) and it always showed me some internal grid’s JS errors. SO finally I configured my columns in code. Grid NEEDs error handling (a customer cannot find out a reason of error judging by some line numbers in internal grid’s code)



Vlad



 


Hello,


you use dynamic loading, don’t you ?


In this case there is no easy way to know when all rows are loaded.


The second parameter of the load method is function that is called right after the initial xml is loaded. So, it is called only once (in case of dynamic paging when the 1st page is loaded).


As the possible solution we can provide you the following approach:


- to set onXLE event handler (onXLE event will be called each time the portion of data is loaded)


- to check if all rows are already loaded


grid.attachEvent(“onXLE”,function(){
for(var i=0; i < this.rowsBuffer.length;i++)
if(!this.rowsBuffer[i]) return;
alert(“All rows are loaded”);
})




rowsBuffer is private property (array of grid rows).


Yes, I use paging, not sure if is dynamic or static, but we load rows in pages not the whole DB.



Thanks for the answer!



Vlad