| Page 1 of 1 | [ 6 posts ] |
|
Hi I wrote a custom sort for a Datatable (I am using Progressive table), and
specified sortedBy this column. However initial sort is wrong or not applied, but when I click on column to sort - it sorts it properly according to my custom sort. Does anyone know why? Here is a code bellow: // Custom sorting data fucntion var sortDate = function(a, b, desc, field) { // Deal with empty values if(!YAHOO.lang.isValue(a)) { return (!YAHOO.lang.isValue(b)) ? 0 : 1; } else if(!YAHOO.lang.isValue(b)) { return -1; } var comp = YAHOO.util.Sort.compare; var compState=0; var aSplit=a.getData(field).split(new RegExp( "[-: ]{1}", "g" )); var bSplit=b.getData(field).split(new RegExp( "[-: ]{1}", "g" )); for(i=0;i<aSplit.length;i++) { compState = comp(aSplit[i], bSplit[i], desc); if(compState!=0) return compState; } }; YAHOO.util.Event.addListener(window, "load", function() { YAHOO.example.EnhanceFromMarkup2 = new function() { var myColumnDefs = [ {key:"start",label:"Start",sortable:true,sortOptions:{sortFunction:sortDate}}, {key:"end",label:"End", sortable:false, sortable:true,sortOptions:{sortFunction:sortLinkDate}}, {key:"error",label:"Error",sortable:true}, {key:"status",label:"Status",sortable:true}, {key:"bug",label:"Bug",sortable:false} ]; this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("statAll")); this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE; this.myDataSource.responseSchema = { fields: [{key:"start"}, {key:"end"}, {key:"error"}, {key:"status"}, {key:"bug"} ] }; this.myDataTable = new YAHOO.widget.DataTable("statMarkup", myColumnDefs, this.myDataSource, {caption:"All Process Stats", sortedBy:{key:"start", dir:YAHOO.widget.DataTable.CLASS_DESC,sortFunction:sortDate}} ); }; }); |
|
SortedBy is meant to tell the DataTable how the data came sorted from the source, so it can apply the proper visual styles. It won't sort the table but if the data came sorted, say, from an SQL server, where sorting is usually cheap, you can tell the DataTable about that.
|
|
Thank you for your response.
How do I make it sort when Datatable renders the first time? |
|
The best is to send it sorted from the server since SQL servers are highly optimized for that.
The next best solution is to sort it in response to dataReturnEvent: http://developer.yahoo.com/yui/docs/YAH ... eturnEvent or doBeforeCallback: http://developer.yahoo.com/yui/datasource/#events |
|
Hi Satyam,
I have the same problem as Vasya, my datatable should get sorted client-side, after loading. Here's my approach: myDataSource.doBeforeParseData = function (oRequest, oRawResponse, oCallback) { /* SORTING*/ var elColumn = myDataTable.getColumn("ColToSort"); if(elColumn != undefined) { myDataTable.sortColumn(elColumn, "ASC"); } return oRawResponse; }; Unfortunately - nothing happens. This code fragment is placed directly after my myDataTable = new YAHOO.widget.DataTable(...) statement. How do I get that work? Is there really no other solution to let YUI sort onload? Thanks for your help, lexx |
|
You can't use sortColumn since the data has not reached the DataTable yet. It has barely reached the DataSource for that matter, it has not even been parsed. You have to use JavaScript's native Array.sort function on the raw response. It will be easier if you try to sort it later, when it is already parsed, either in doBeforeCallback or in DataTable's doBeforeLoadData
|
| Page 1 of 1 | [ 6 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© YUI Library - Site Credits
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group