custom sort not working

Hello there!



It seems custom sorting is not working in my version. I still use Professional Version 1.4, since I started to develop application before version 1.5 was available.



I defined the sort types by:



mygrid.setColSorting(str,str,sort_custom,sort_custom,…);



Then i have this function:



function sort_custom(a,b,order)

{

alert (order);

}



I just tried if function is entered and it seems it is not. It doesnt alert anything. I think files have some errors or anything else.



How can i fix it?



And: How can i upgrade from 1.4 to 1.5 in an existing application? Do I only need to overwrite old DHTML files or is there any risk that application gets inconsistent when i do this?



Thx in advance!

The local samples of dhtmlxgrid 1.4 works fine with custom sorting , there were no known issues related to sorting.
Please be sure that sort_custom function was already defined on moment of setColSorting call.

You can check  next sample inside your package
    samples/pro_sort.html

If problem still occurs for you - please contact us directly at support@dhtmlx.com - we may send the latest build of dhtmlxgrid 1.4 ( it contains all fixes before 1.5 releasing, and may resolve some issues )

>> And: How can i upgrade from 1.4 to 1.5 in an existing application?
Do I only need to overwrite old DHTML files or is there any risk that
application gets inconsistent when i do this?

There were no significant changes in logic and API fully backward compatible, so just updating js files will be enough
Latest version of dhtmlxgrid for now is 1.6 - upgrade for 1.6 is bit more complex because of changes in event system and paging extension.

I am sure that sort_custom function is already defined on moment of setColSorting call, but it is still not working. When I initialize the JS-File and call sort_custom function (for ex sort_custom(1,2,“asc”)) anywhere in the script for test purposes, it does enter, but it never enters function when I click on the header to sort a column.

Already checked the sample and I am quite sure I didn’t do any mistake…

I had these problems before in another respect, I sent you all my files regarding this issue and answer was that it was working fine at your side but it never worked on my side! So I guess there is still an issue with your source files.

If problem still occurs for you - please send any kind of sample where it can be reconstructed ( or any kind of demo link ) to support@dhtmlx.com

The custom sorting will not be call ( in dhtmlxgrid 1.4 )
- when smart rendering used
- onBeforeSorting event attached, and it doesn’t returns true
- custom sorting in left part of splitted grid may be problematic in some cases

It is still not working. I tried already all of these things and function is just never entered. I am quite sure that it has something to do with the source files. I can send you my files. But there is only a alert-function in my custom sorting function which is never shown. Could it be that custom sorting is not working for TreeGrid? Because I am using it in this case!

Here is initialisation of grid (some headers are dynamic):

function initOrganisationGrid(year,quarter)
{
    myGridbox = new dhtmlXGridObject(‘gridbox’);
    myGridbox.setImagePath(documentRoot+"/include/dhtmlx/imgs/");
    myGridbox.setSkin(“gray”);
    myGridbox.enableColumnAutoSize(true);
    quarters = getQuarters(year,quarter);
    myGridbox.setHeader(“Organisation / Customer Description,12NC,<span style=“color:#008000”;>”+quarters[0]+" (EUR),<span style=“color:#008000”;>"+quarters[1]+" (EUR),<span style=“color:#008000”;>"+quarters[2]+" (EUR)</span,<span     style=“color:#008000”;>"+quarters[3]+" (EUR),<span style=“color:#5F5F5F”;>"+quarters[4]+" (EUR),<span style=“color:#5F5F5F”;>"+quarters[5]+" (EUR),<span style=“color:#5F5F5F”;>"+quarters[6]+" (EUR),<span                 style=“color:#5F5F5F”;>"+quarters[7]+" (EUR),Status,Region InvoiceTo, Country InvoiceTo, Invoice From");
    myGridbox.setInitWidths(“320,90,55,55,55,55,55,55,55,55,45,65,85,65”);
    myGridbox.enableResizing(“true,true,true,true,true,true,true,true,true,true,true,true,true,true”);
    myGridbox.setColAlign(“left,left,right,right,right,right,right,right,right,right,center,left,left,left”);
    myGridbox.setColTypes(“tree,link,rocustom,rocustom,rocustom,rocustom,rocustom,rocustom,rocustom,rocustom,img,ro,ro,ro”);
    myGridbox.setColSorting(“str,str,sort_custom,sort_custom,sort_custom,sort_custom,sort_custom,sort_custom,sort_custom,sort_custom,str,str,str,str”);
    myGridbox.enableAlterCss(“gridEven”,“GridUneven”);
    myGridbox._srdh=rowHeight;
    myGridbox.init();
    try{
        myGridbox.setOnLoadingEnd(loadingEnd);
    }catch(e){}
    myGridbox.setOnLoadingStart(showLoading);
    //window.s_col=1;
    myGridbox.enableSmartXMLParsing(true);
    organisationReloadGrid();
}

function organisationReloadGrid()
{
    myGridbox.clearAll();
    myGridbox.kidsXmlFile = “ajax/getOrganisationList.php”;
    myGridbox.loadXML(“ajax/getOrganisationList.php”);
}

function sort_custom(a,b,order)
{
    alert("a: "+a);
    alert("b: "+b);
    alert("order: "+order);
    alert (“test”);
}

Here is the XML which is returned:

<![CDATA[APPLE (45102)]]>
<![CDATA[2403 252 28828]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 260 00001]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 260 00017]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[FOXCONN (APPLE) (45107)]]>
<![CDATA[2403 260 00017]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[FOXCONN (APPLE) (45109)]]>
<![CDATA[2403 260 00017]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[GR.CHINA]]>
		<![CDATA[Hong Kong]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 260 00029]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 260 00031]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 260 00032]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[FOXCONN SHENZEN (APPLE) (26100)]]><
/cell>
<![CDATA[2403 260 00032]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[GR.CHINA]]>
		<![CDATA[China]]>
		
	
<![CDATA[HON HAI SHENZEN (APPLE) (45105)]]><
/cell>
<![CDATA[2403 260 00032]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[GR.CHINA]]>
		<![CDATA[China]]>
		
	
<![CDATA[NXP RDC HONG KONG (45017)]]>
<![CDATA[2403 260 00032]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[GR.CHINA]]>
		<![CDATA[China]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 260 00035]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	
<![CDATA[APPLE (45102)]]>
<![CDATA[2403 262 00049]]>
		
		
		
		
		
		
		
		
		
		<![CDATA[AMERICAS]]>
		<![CDATA[USA]]>
		
	


I am using a custom excell type to be able to show different colors in different columns.

The sample with the same code (except of column type, because we have not code of rocustom excell ) works correctly with dhtmlxgrid 1.4 code
Sample has been sent by email.

If problem still occurs for you - please try to use js files from provided sample ( this is latest build of dhtmlxgrid 1.4 , which may differ from files used in your case )

Thx, it is working now. Source Files were indeed not working correctly!

But now there are some other problems which I did not have with former files. If there is a menu item opened in the tree and I want to sort by a special column the items from the tree (menu items) move to another position in the grid (another row) every time I click on the column. I tried to use older files again and it does not show a behaviour like that. What could be wrong?

Thx in advance!

No idea for my previous question??

Is there any difference regarding custom sorting to take into account when you are using TreeGrid instead of Grid? When I click on a column to sort position of menu items are moving to other rows. But i think this is not usual behaviour because main items should stay in the row where they are and only sub-items in an open menu-item should change, right?


I have defined a custom excell type to be able to show different columns in different colors. Here is the source code:

function eXcell_rocustom(cell)
{
    try
    {
        this.cell = cell;
        this.grid = this.cell.parentNode.grid;
    }
    catch(er)
    {}
    this.edit = function()
    {
        return false;   
    }
    this.getValue = function()
    {
        return this.cell.innerHTML.toString();;
    }
    this.setValue = function(val)
    {
        if(val.toString()=="")
        {
            val = " “;   
        }
        else
        {
            if (val.toString().indexOf(”#") != -1)
            {
                color = val.toString().substr(0,7);
                val = val.toString().substring(val.indexOf("_")+1);
                if (val < 1)
                {
                    val = “0”+val;
                }
                val = parseFloat(val).toFixed(4);
                val = “<span style=“color:”+color+”;">"+val+"";
            }
            else
            {
                if (val < 1)
                {
                    val = “0”+val;
                }
            }
        }
        this.cell.innerHTML = val;
    }
    this.detach = function()
    {
        return false;
    }
}
eXcell_rocustom.prototype = new eXcell;

So most of the values (except empty ones) within the cells are:

0,4896

custom sorting function is:

function sort_custom(a,b,order)
{
   
    if (a != " “)
    {
        a = a.substring(a.indexOf(”>")+1, a.lastIndexOf("<"));
    }
    if (b != " “)
    {
        b = b.substring(b.indexOf(”>")+1, b.lastIndexOf("<"));
    }
    if (order == “asc”)
    {
        return a>b?1:-1;
    }
    else
    {
        return a<b?1:-1;
    }
}

What could be wrong? Thx in advance!

Is there any difference regarding custom sorting to take into account when you are using TreeGrid instead of Grid?
Basically it works the same. The only difference is that stable sorting (grid.enableStableSorting) available for plain grids only

>>If there is a menu item opened in the tree and I want to sort by a
special column the
>> items from the tree (menu items) move to another
position in the grid (another row) every time I click on the column.
I checked the same code as in your case - and it works correctly for me in local samples. The hierarchy structure not corrupted. The items may shift their position inside the same parent ( this is caused by used sorting approach )

If problem still occurs for you  - please send any kind of sample where issue can be reconstructed to support@dhtmlx.com

I dont know, it is still not working. Could it be that it does not work because the files you sent to me (newer version of 1.4) where in lower cases, but mine include capitals as well. For example the files you sent me look like dhtmlxcommon.js but within my application it is dhtmlXCommon.js. It doesnt work if i do not change the capitals in the file. But could it be that it does not work because i renamed the files?

Thx in advance!

Started from dhtlmxgrid 1.5 all file names was lowercased.
The casing itself must not cause issue ( if it is incorrect, wile would not be loaded, and grid will not render at all ), renaming files is safe as well.

I just tried to upgrade from Version 1.4 to Version 1.5. I started the application with 1.4 but because there are some source files not working correctly I wanted to upgrade. I was told that I only need to overwrite old files with the new ones from version 1.6. But when I do this and want to load treegrid it says: "dhtmlxHierarchy is not defined"

What could be wrong?

Could you do me a favour again, please? Because custom sorting is not working with my source files could you please send me all necessary files which is concerned with the TreeGrid and custom sorting? And please files from latest release of version 1.4.

I am using the Professional Edition. If it doesnt work then, i give up!!

Working samples of custom sorting with both dhtmlxgrid 1.4 and dhtmlxgrid 1.5 sent by email
The issue may be caused by old version of grid, but the js file, which was sent previously , must resolve issue.

Didnt get a mail with a sample or do you mean the mail you sent me last time?

Well, the issue is solved with these files, at least for custom sorting. But now there is another problem. Whenever I want to sort by a column the items in the grid move to another position, not only the child items, but also the not opened items. This issue didnt occur when I used old version with which custom sorting was not possible so I assume this new issue has to do with new files too. Grid doesnt work if I keep the source files in lower cases, have to adapt it to old style. I just would like to have some working files,  we are paying for these files and  it seems they never work. Custom sorting didnt work at all, now it is working, but another problem arised.

Do I have to overwrite the CSS files from my applications with the files from your sample too? Or only the JS-Files? Do I have to use the codebase folder or just use the folder where the files are placed in at the moment?

I think my problems would be solved if I could upgrade within the existing application from Version 1.4 to 1.5. I was told here that I only have to overwrite existing files (1.4) with files from Version 1.5. But this is not working. It says: dhtmlXHierarchy is not defined. So how do I upgrade?

>>Didnt get a mail with a sample or do you mean the mail you sent me last time?
I checked and it seems that they really still not sent. We still await the info about your reference number ( This number was sent to you with the download link to the purchased product right after purchase. )

>>I want to sort by a column the items in the grid move to another
position, not only the child items, but also the not opened items
If items has the same value for sortin column they can change their position ( use sorting way - quicksort - is fast , but doesn’t preserve previous order of items )

>>Do I have to overwrite the CSS files from my applications with the files from your sample too? Or only the JS-Files?
If you are using the same version of grid as in sample - the usage of dhtmlxtreegrid.js from it must be enough.
If you are using older version - all files, including css ones, need to be replaced

>>It says: dhtmlXHierarchy is not defined. So how do I upgrade?
You need to update both dhtmlxGrid and dhtmlxTreeGrid to the same version ( 1.5 in your case ). Mentioned error may occur if you are using different versions of Grid and TreeGrid in same time.

Oh, sorry, forgot the reference number.

It is 107255055

Thx