Author Topic: Sorting by central europe date format  (Read 3556 times)

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Sorting by central europe date format
« on: February 09, 2016, 09:47:19 pm »
Hi,
I have a problem sorting a column with localized Central Europe date format (dd/mm/yyy); I was wrong about something or I need to implement some custom sorting?

Thank you for help.

Code: [Select]
$(function () {
        var data = [
[1, 'Exxon Mobil', '20/02/2015', '339,938.0', '36,130.0'],
            [2, 'Wal-Mart Stores', '01/01/2016', '315,654.0', '11,231.0'],
[3, 'Royal Dutch Shell', '01/12/2015', '306,731.0', '25,311.0'],
[4, 'BP', '20/02/2016', '267,600.0', '22,341.0'],
[5, 'General Motors', '31/12/2016', '192,604.0', '-10,567.0'],
[11, 'ZZZ General Electric', '20/02/2017', '157,153.0', '16,353.0']
]


        var obj = {
            scrollModel: {autoFit: true},
            height: 400,
            colModel: [
                { title: "Rank", width: 100, dataType: "integer" },
                { title: "Company", width: 200 },
                { title: "Date", width: 180, dataType: "date" },
                { title: "Revenues ($ millions)", width: 180, dataType: "float" },
                { title: "Profits ($ millions)", width: 180, dataType: "float" }
            ],
            dataModel: {
                data: data,
                sortIndx: 2,
                sortDir: "up"
            }
        };

$.extend($.paramquery.pqGrid.prototype.options, $.paramquery.pqGrid.regional['it']);
$.extend($.paramquery.pqPager.prototype.options, $.paramquery.pqPager.regional['it']);

        $("#grid_custom_sorting").pqGrid(obj);
    });


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Sorting by central europe date format
« Reply #1 on: February 09, 2016, 10:46:47 pm »
It's better to keep the date values in mm/dd/yy or ISO 8601 format yy-mm-dd, which javascript can easily parse.

The dates can be displayed in European date format (dd/mm/yyy) in column.render callback.

render: function( ui ){
  return $.datepicker.formatDate( 'dd/mm/yy', new Date( ui.cellData ) );
}

https://api.jqueryui.com/datepicker/#utility-formatDate
« Last Edit: February 09, 2016, 10:52:30 pm by paramquery »

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Sorting by central europe date format
« Reply #2 on: February 10, 2016, 03:21:31 pm »
Thank you, it's a possibility but it seems too complex because it's an application with many date fields that go TO and FROM a database (inserted from manual input) and the dates of the database are used by another application that use the standard European format.

Is it possible to order a column with the values of another hidden column?

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Sorting by central europe date format
« Reply #3 on: February 10, 2016, 03:33:19 pm »
Ok, it seems that it's possible using the custom sorting like in http://paramquery.com/pro/demos (Sorting -> Custom Sorting)

Thank you