Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Mathijs Gaalman on May 04, 2009 02:20
open dhtmlx forum
DHTMLgrid & Sorting

I have an DHTMLgrid which is loaded through an XML file.
The first column is a link. These links can be in the form:
#fileName#^#Documentname#
#fileName#^document.cfm?=#Documentname#

the fileName can be locationondisk/files/filename or locationondisk/filename

When is sort this column it makes a sortation not on the documentname, but on the resulting URLS. therefore the documentNames are not sorter correcty.

How can i get the sorting of this colum get to sort on the documentnames which i see in the column?
Answer posted by dhxSupport on May 04, 2009 05:30
While sorting grid takes getValue() from the cell and filter grid depending on this value. getValue() method from the "link" eXcell type will return string with a full path to your file. To change that behaviour you can implement custom eXcell type. Please see more information here http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Custom_excell_creation.html#grid_cexc
Answer posted by mathijs gaalman on May 18, 2009 12:30
I've tried using an Excell type, using a script, but with no good results. This is the code i use:


            function eXcell_AOtext(cell){             //excell name is defined here
                if (cell){                                  //default pattern, just copy it
                    this.cell = cell;
                    this.grid = this.cell.parentNode.grid;
                }
                this.edit = function(){}            //read-only cell doesn't have edit method
                this.isDisabled = function(){ return true; }      // the cell is read-only, that's why it is always in the disabled state
                this.setValue=function(val){
                var temp = val.split("^");
                name  = temp[0];
                url  = temp[1];
                target  = temp[2];
                urlNew = 'javascript:openDocument("'+url+'");';
                    this.setCValue("<a name='"+name+"'href='"+urlNew+"'>"+name+"</a>",val);
                }
            }
            eXcell_AOtext.prototype = new eXcell;    // nest all other methods from base class


See also attachment what happens

Can you provide a code sample for me?
Attachments (1)
Capture.PNG12.13 Kb
Answer posted by Alex (support) on May 18, 2009 23:14

Hello, 

You didn't define getValue() method for your excell. 

Actually get use a ready link excell. dhtmlxgrid_excell_link.js, but in this case you should redefine its getValue() method as you need. Currently it returns following value:

this.cell.firstChild.innerHTML+"^"+this.cell.firstChild.getAttribute("href")

It means - link_title^url. 

You need to return an url or part of it  (this.cell.firstChild.getAttribute("href") ) from getValue method

Answer posted by Mathijs Gaalman on May 19, 2009 11:30
I see what you mean, but i think these custom excells have more to do with the presenation of the link within the cell.
The problem i have is with the sorting of the column. It now sorts on the Link_url string. I want to have it sorting on the Link_title name string. How do i do that?
Thanks in advance.
Answer posted by Support on May 20, 2009 05:51
Sorting routine use getValue method of excell to get text by which row will be sorted. 
So you can create a custom getter , which will return any necessary value.

eXcell_AOtext.prototype.getValue=function(){
       return this.cell.getAttribute("name"); //or any other value 
};


Answer posted by mathijs on May 20, 2009 12:49
thanks, this helped me a lot!