Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Heather Mann on Jan 14, 2010 17:47
open dhtmlx forum
Grid sort doesn't update after updateFromXML

I have a form which adds a record to the database, I then reload the XML with updateFromXML which works fine except I can't seem to get the grid to resort, the new record is always added to the bottom of the grid. If I page refresh then it's sorted properly.

--GRID CODE--

mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setImagePath("/dhtmlx/dhtmlxGrid/codebase/imgs/");
mygrid.setHeader("Date, Category, Description, Points");
mygrid.setColSorting("date,str,str,int");
mygrid.setInitWidths("80px,100px,140px,60px");
mygrid.setColTypes("ro,ro,ro,ro");
mygrid.setColAlign("center,center,center,center");
mygrid.init();
mygrid.setSkin("light");
mygrid.load("/xml/members_data.php");


--POST FORM DATA CODE--

    $(document).ready(function(){
        $("form#earnedspent_request").submit(function() {
            var memberPoint_id= c3.getSelectedValue();
            $.ajax({
                url: "/submit/register.php?memberPoint_id="+memberPoint_id,
                success: function(){
                    mygrid.updateFromXML("/xml/members_data.php", true, true);
                    mygrid.sortRows(0,"date","des");
                }
            });
            return false;
        });
    });

Any pointers in the right direction would be most appreciated.


Answer posted by Stanislav (support) on Jan 15, 2010 02:42
Updating is async. process , so to call sorting after data loading you need to have


 mygrid.updateFromXML("/xml/members_data.php", true, true, function(){
     mygrid.sortRows(0,"date","des");
}); 
   
Answer posted by Heather on Jan 15, 2010 07:52
Worked perfectly.  Thanks.