Author Topic: Issue with sorting column containing float values  (Read 3419 times)

Lakshmi

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 10
    • View Profile
Issue with sorting column containing float values
« on: May 16, 2017, 04:33:41 pm »
I am using currently PRO Version of PQ grid. I have already gotten in touch with PQ -Grid team via mail, where-in the reply was to add "datatype:float". I have been using datatype:float in the column and initiating it when getting data, i.e.in  "Getdata" function, as here we use Remote method and column bindings are dynamic. Other data types like Integer, Date works just fine except the float. Please help if there is something that's missing. Once column model is build, it is binding to grid, as below :

Grid.option("colModel", columnmodel);

This is how the obj is built :
columnmodel.push(
            {
                title: "PRICE",
                dataIndx: "price",
                editable: false,
               
            });
//say if Price is in index 0,
        if (columnName == "PRICE") {
            columnmodel[0].dataType = 'float';
        }

It gets sorted wrongly like this :

109.51
111.74
112.57
1124.08
113.14
113.5
Kindly advise
« Last Edit: May 16, 2017, 04:47:51 pm by Lakshmi »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Issue with sorting column containing float values
« Reply #1 on: May 16, 2017, 08:25:53 pm »
In addition to dataType: 'float',

all the values in column should be stored as numbers instead of strings i.e., 109.51 instead of '109.51'

If the data in grid is fetched from JSON data, then

values should be like this "price": 109.51 instead of "price": "109.51"
« Last Edit: May 16, 2017, 08:28:59 pm by paramquery »

Lakshmi

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Issue with sorting column containing float values
« Reply #2 on: May 16, 2017, 08:29:10 pm »
Hi ,Thank You for your prompt reply.

Since we are binding it as JSON object, all the values will be bound as string.

Also,I had this doubt as well, so in the render of the column, I return the celldata as parsefloat(ui.celldata) and it still worked incorrectly.

Further, I have one more query. The same logic works fine for Integer and Date, where there is no explicit conversion of values and everything is bindided as JSON object.

Please advise.

Regards,
Lakshmi

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Issue with sorting column containing float values
« Reply #3 on: May 16, 2017, 09:51:50 pm »
Quote
Since we are binding it as JSON object, all the values will be bound as string.

JSON can contain numbers, please check the freight values in sample JSON data: https://paramquery.com/Content/orders.json?pq_datatype=JSON&_=1494950795504

Quote
Also,I had this doubt as well, so in the render of the column, I return the celldata as parsefloat(ui.celldata) and it still worked incorrectly.

column.render is used for view rendering of cells in the viewport, but not to change/convert the cell value.

Quote
Further, I have one more query. The same logic works fine for Integer and Date, where there is no explicit conversion of values and everything is bindided as JSON object.

Dates are bound as strings in JSON as can be seen in "OrderDate":"05/08/1997" in sample JSON data. Integers should be bound as numbers similar to floats i.e., 1000 instead of "1000".
« Last Edit: May 16, 2017, 09:55:47 pm by paramquery »