Sort order is not maintained for Excel export

Sort order is not maintained for excel export from dhtmlx grid. Randomly displayed in the excel after export from dhtmlxgrid. This is happened for after sorting the dhtmlxgrid.

Below is the code for your reference:

        mygrid.enableMultiselect(true);
        var count = mygrid.getSelectedId();
        if (count != null) {
            var mySplitResult = count.split(",");
            mySplitResult.sort(function (a, b) {
                mygrid.getRowIndex(a) > mygrid.getRowIndex(b) ? 1 : -1
            })


            var rowcount = 0;
            for (j = 0; j < mySplitResult.length; j++) {
                mygrid.selectRow(mygrid.getRowIndex(mySplitResult[j]), false, false, false);
                if (mySplitResult[j] == ',') {
                    rowcount++;
                }
            }
        }

        if (count != null || count != "") {
            mygrid.toExcel("Generator/GenerateExcel", null, false, false, mySplitResult);
            for (j = 0; j <= mySplitResult.length; j++) {
                mygrid.selectRow(mygrid.getRowIndex(mySplitResult[j]), true, true, true);
                if (mySplitResult[j] == ',') {
                    rowcount++;
                }
            }
        }
        else
       mygrid.toExcel("Generator/GenerateExcel");

Thanks for your support.