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", field2:100 },
{ field1:"50", field2:50 }
]
}
Field1 as a column in a datatable will sort incorrectly, field2 will sort
correctly. Make sure that the data coming back in the json is correctly
(syntactically) represented.
I, for example, am normally converting blobs of stuff in a array (from a
database lookup) into json, and I use a helper function to do that which scans
each field and determines if it should be quoted or not. Something like this
(PHP):
function makeJSON ($a) {
// get the keys
$keys = array_keys($a);
$cols = sizeof($keys);
// make the data string
$json = "";
for ($c=0; $c<$cols; $c++) {
$k = $keys[$c];
$val = $a[$k];
$o = $n = $d = 0;
$sz = strlen($val);
for ($i=0; $i<$sz; $i++) {
$x = substr($val,$i,1);
if ((($x == '-') || ($x == '+') ||
($x == '.')) && ($i == 0)) ++$n;
elseif (($x >= '0') && ($x <= '9')) ++$n;
elseif (($x == '.') && ($d == 0)) ++$d;
else ++$o;
}
if (($o == 0) && ($n > 0) && ($d <= 1)) $v = $val;
else $v = "'" . jsSafe($val) . "'";
$json .= ($c==0?" ":", ") . "$k:$v";
}
// return the snippet
return ($json);
}
Note: jsSafe is just a function that makes sure any necessary characters are
"escaped" in the string to make it a legal javascript string.
Hope that helps...
~~bret
--- In
ydn-javascript@yahoogroups.com, "Crazy Serb" <gusic@...> wrote:
>
> 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...
>