DataView => problem with simple sorting after loading

Hello,

My problem is quite simple:

I created a DataView within a dhtmlxWindows with the following code:

<script>
datacats = new dhtmlXDataView({
    container: "data_container",
    drag: true,
    type: {
        template: "#prior# : #title#<br/>#description#",
        height: 40
    }
});

datacats.load("update_cats.php");

var dpcats = new dataProcessor("update_cats.php");
dpcats.init(datacats);

dpcats.setUpdateMode("cell");

//alert("hello");

datacats.sort("#prior#","asc","int");
</script>

Unfortunately, the last line (datacats.sort…) does not work. My data still displays unsorted.

However, if I just uncomment the alert(“hello”); line, it actually works after the alert box is closed. How is that possible?

Similarly, if I simply add the following button right after the tag, it works (when clicked):

<button onclick="datacats.sort("#prior#,"asc","int");">

My question is thus: why doesn’t the sort function work when not preceded by my alert function or without any action from the user? Or how is it possible to have my data “automatically” sorted after it is loaded?

Thanks a lot for any help. I spent a lot of time on this, but I feel lost…

You should wait till all data is loaded:

datacats.load("update_cats.php",function(){ datacats.sort("#prior#","asc","int"); });

Thank you very much, this worked. I was actually looking for a kind of “onAfterLoaded” event and was not aware that a function could be called directly in the load function.

Thanks again!