Search the web
Sign In
New User? Sign Up
ydn-javascript · Yahoo! User Interface Library Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
DataTable numbers/float values not sorted properly   Message List  
Reply | Forward Message #50214 of 52114 |
Ok, I've tried a few suggestions from people around here, and nothing so
far has worked - the numbers still get sorted as if they were strings:

Total Net Value:
0.441
101.404
107.558
107.558
108.48
108.945
11.195
12.143
12.801
131.73

Here is what I've got as far as the code goes:

<code>
YAHOO.example.DynamicData = function() {
// Column definitions
var myColumnDefs = [
{key:"NAME", label:"Name", width:200, resizeable:true,
sortable:true},
{key:"DATE", label:"Start Date", formatter:"date"},
{key:"NET", label:"Total Net Value", sortable:true}
];

// DataSource instance
var myDataSource = new YAHOO.util.DataSource("/?json&");
myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
myDataSource.responseSchema = {
resultsList: "records",
fields: [
{key:"NAME"},
{key:"DATE"},
{key:"NET", parser:"number"}
],
metaFields: {
totalRecords: "totalRecords",
paginationRecordOffset : "startIndex",
paginationRowsPerPage : "pageSize",
sortKey: "sort",
sortDir: "dir"
}
};

// DataTable configuration
var myConfigs = {
initialRequest: "sort=NAME&dir=asc&startIndex=0&results=15", //
Initial request for first page of data
dynamicData: true, // Enables dynamic server-driven data
sortedBy : {key:"NAME", dir:YAHOO.widget.DataTable.CLASS_ASC},
// Sets UI initial sort arrow
paginator: new YAHOO.widget.Paginator({
rowsPerPage: 25,
template: YAHOO.widget.Paginator.TEMPLATE_ROWS_PER_PAGE,
rowsPerPageOptions: [10,25,50,100],
pageLinks: 3
})
};

// DataTable instance
var myDataTable = new YAHOO.widget.DataTable("tab1", myColumnDefs,
myDataSource, myConfigs);
// Update totalRecords on the fly with value from server
myDataTable.handleDataReturnPayload = function(oRequest, oResponse,
oPayload) {
oPayload.totalRecords = oResponse.meta.totalRecords;
return oPayload;
}

return {
ds: myDataSource,
dt: myDataTable
};

}();
</code>


What am I missing here? This is driving me bananas...





Fri Jul 3, 2009 6:39 pm

realcrazyserb
Offline Offline
Send Email Send Email

Forward
Message #50214 of 52114 |
Expand Messages Author Sort by Date

Ok, I've tried a few suggestions from people around here, and nothing so far has worked - the numbers still get sorted as if they were strings: Total Net...
Crazy Serb
realcrazyserb
Offline Send Email
Jul 3, 2009
6:39 pm

This is a guess since I can't see your data, but I suspect the json coming back has the value(s) as string. For example: { count:2, rows:[ { field1:"100",...
bretlevy
Offline Send Email
Jul 4, 2009
4:04 pm

That's probably it, as I can only get a hold of json data with all fields/values in quotes... and I would have to go through that list AFTER the fact and...
Crazy Serb
realcrazyserb
Offline Send Email
Jul 6, 2009
3:42 pm

It should, indeed, parseNumber will convert a string of digits into a number, either integer or float (basically, multiplies whatever the value by 1). I...
Satyam
satyamutsa
Offline Send Email
Jul 6, 2009
4:09 pm

Add an event listener for initEvent and then put a debugger statement in the listener. myDataTable.on('initEvent', function() { debugger; ...
Satyam
satyamutsa
Offline Send Email
Jul 6, 2009
6:23 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help