Accessing Grid After Load

I need to access the grid data after it has been loaded to initialize some features. I have tried using load() with a callback and the “onxle” event but neither appear to be very reliable. I am seeing that sometimes the dataset is not accessible in the callback:

$$(_a.NAME + '_grid').attachEvent("onxle", dhx.bind(_a.onAfterLoad, _a));

onAfterLoad: function () {
    var _a = this;

    try {

        // Fetch the total records number
        if ($$(_a.NAME + "_grid").dataCount() < 1) {
            _a.notify("No records found", "Data Loading");
        }
        else {
            // Sometimes the first record is 'undefined'
            _a.dataCount = $$(_a.NAME + "_grid").item($$(_a.NAME + "_grid").first()).userData.total;
        }

    } catch (e) {
        _a.Error("onAfterLoad", e);
    }
},

onXLE occurs after parsing. Therefore, data are available in this event handler. The event is also called in case of loading error. Therefore, please check that items are loaded.

Is there a more reliable test than getting the datacount?

$$(_a.NAME + "_grid").dataCount();

You can set complex loading handler as in:

$$("grid").load(url, "json", { success: function(){ alert(this.dataCount()) }, error: function(){ alert("error") } });