WelcomeForumsCommunityGrid – Datetime format

Wijmo Team Member
AlexPaterson posted on June 4, 2012 at 8:09 am link

Hi everybody.
I’m evaluating wijmo to be used in our company’s intranet.
I’m having some issues with the datetime format shown in wijmo Grid.
I am using the grid on an HTML table, formatted this way :

Data Descrizione Note Quantità
2012-10-12 ACDC Laptop Alimentatore per Merch 1 M   X

And using this to make it a wijmo grid :

$(“#tabella”).wijgrid({
allowPaging: true,
pageSize: 20,
pagerSettings: { position: “bottom” },
allowSorting: true,
scrollMode: “horizontal”,
showFilter: true,
ensureColumnsPxWidth: true,
showFooter: true,
columns: [
{dataType: "datetime", dataFormatString: "yyyy-mm-dd", width:130 },
{dataType: "string", allowSort: false, width:300 },
{dataType: "string", allowSort: false, width:300 },
{dataType: "number", allowSort: false, width:120, dataFormatString: "n0" },
{footerText: " NEW ", showFilter: false, allowSort: false, width:50}
],

});

The problem is :
When I am enabling search on the datetime column, every row shows dates in the right format ( yyyy-mm-dd ) but the search box shows date this format : ( mm/dd/yyyy ) and it does not work properly on my rows.

Is there a possibility to :

- Read dates in a format but showing them in another one
- Change the search box format for date columns
- Make my datetime column work ?

Thanks !
Simone

Wijmo Team Member
sergeys posted on June 5, 2012 at 2:44 am link

The fix for this issue will be available in the next release.
As a workaround you can globally redefine the “d” pattern used by default by wijgrid and wijinputdate:

        Globalize.cultures['default'].calendar.patterns['d'] = ‘yyyy-MM-dd’;

Filter may work incorrectly due to non-zero time portion in the filter value as filter editor uses the current datetime if filterValue is not set. You can truncate time portion at run-time:

        $(‘#demo’).wijgrid({
                showFilter: true,
                data: [
                        [0, new Date('01/01/2011')],
                        [1, new Date('06/30/2012')],
                ],
                columns: [
                        { },
                        { dataType: 'datetime' }
                ],
                filtering: function (e, args) {
                        if ((args.column.dataType === ‘datetime’) && (args.value instanceof Date)) {
                                args.value = new Date(args.value.toDateString());
                        }
                }
        });
Answer
Wijmo Team Member
AlexPaterson posted on June 6, 2012 at 8:01 am link

Bella zio.
Thank you !

Answer
Wijmo Team Member
AlexPaterson posted on June 26, 2012 at 8:52 am link

Hi everybody.
First of all, lots of thank you for the gorgeous work you’re doing: Wijmo is a really great collection of API.

I’m updating my experience with this wijmo grid issue after trying version 2.12.
Using dataType: “datetime” on my column ( yyyy-mm-dd ) works on internet explorer but stops on the “loading” screen if using Firefox and Safari.

Besides that, the “equals” filter does not work on dates, even using IE.
And the “BeginsWith” filter does not work on strings.

Just saying, so that you can check :)
Bye

Simone

Answer
Wijmo Team Member
sergeys posted on June 27, 2012 at 12:07 am link

I would need a small working sample for all three problems as I cannot reproduce any of them

1. datetime + “yyyy-mm-dd”
2. Not working filter BeginsWith + strings
3. Not working filter Equals + dates

BTW, you specified “mm” token in dataFormatString, this denotes munites, “MM” – months seems more logical to me.

Answer
Wijmo Team Member
AlexPaterson posted on June 27, 2012 at 2:15 pm link

Sorry, I am using MM for month infact.

Anyway, my DOM table is :

Data Quantità Descrizione Note
2012-02-13 4 Monitor Sede M   X
2012-02-13 4 Monitor per sede Monitor per sede M   X
2011-12-30 0 Assistenza Mensile Sede 12/11 Assistenza Mensile Sede 12/11 M   X
2011-12-02 20 Zebra Stores M   X

And my Wijmo grid is defined by this code:

$(“#tabella”).wijgrid({

allowPaging: true,
pageSize: 20,
pagerSettings: { position: “bottom” },
allowSorting: true,
scrollMode: “horizontal”,
showFilter: true,
ensureColumnsPxWidth: true,
showFooter: true,
columns: [

{ dataType: "datetime",
dataFormatString: "dd/MM/yyyy",
width:140
},

{ dataType: "number",
allowSort: false,
dataFormatString: "n0",
width:120
},

{ dataType: "string",
allowSort: false,
width:300
},

{ dataType: "string",
allowSort: false,
width:300
},

{ footerText: " NEW ",
showFilter: false,
allowSort: false,
width:50
}

]});

I’m sorry I pasted lots of code, but I hope this will be of any help.
Thank you !

Simone

Answer
Wijmo Team Member
sergeys posted on June 29, 2012 at 12:36 am link

I can’t see any of the issues you mentioned in IE9\ FF 13 (check my sample attached to this post).

There is a problem that if user does not edit a filter value for datetime column the filter is not applied, this will be fixed in the next version.

In Safari browser there is a problem with dates in the “yyyy-MM-dd” format as Date.parse in Safari cannot parse ISO-8601 dates.

I can see two options here:

1. Make the source table to initially conform the dataFormatString pattern.
2. Use a custom parser for date columns:

   var myDateParser = {
      parse: function (value) {
         var result = $.wijmo.wijgrid.embeddedParsers.dateTimeParser.parse.apply(this, arguments);
         if (!result) {
            // convert value to Date object manually
         }
      },

      toStr: function (value) {
         return $.wijmo.wijgrid.embeddedParsers.dateTimeParser.toStr.apply(this, arguments);
      }
   }

  $(‘#demo’).wijgrid({
    columns: [
       { dataType: "datetime", dataParser: myDateParser}
    ]
  });
 
Attachments:
  1. sample1.zip
Answer
Wijmo Team Member
AlexPaterson posted on June 29, 2012 at 7:42 am link

Thank you sergeys for your answer !
I’m checking with your sample but I still can’t make the “Equal” filter work on dates.
I am doing the following actions on your sample:
- Insert 03/12/2012 as search date
- Press “Greater than” and see 04 – 05 – 06 / 12 / 2012. ( Correct )
- Press “Equals” and see no line. ( Not Correct ).

I do not know if this is an issue with my localization, I am using an Italian version of Firefox 13 and IE 9.
I have tried adding the line

script src=”http://cdn.wijmo.com/external/cultures/globalize.culture.it-IT.js”
type=”text/javascript

To the imports. But with no result.

As per the issue about grid stuck in loading screen, your sample works and my table does not. I’ll check :)

Thank you again !
Simone

Answer
Wijmo Team Member
AlexPaterson posted on June 29, 2012 at 8:18 am link

I found what the “loading” screen issue is :

If the date field in my DOM table is indented this way :

>TD>
2012-12-12
>/TD>

The grid does not work in Firefox and Safari.
If it is not indented

>TD> 2012-12-12 >/TD>

It works and loads Wijmo grid correctly.

Answer
Wijmo Team Member
sergeys posted on July 2, 2012 at 6:46 am link

The problem with TD formatting will be fixed in the next release of wijmo.

As for DateTime + Equals:
You need to truncate time part from the value obtained by wijgrid from wijinput as it may be there.

  filtering: function (e, args) {
        if (args.column.dataType === ‘datetime’ && args.value instanceof Date) {
                args.value = new Date(args.value.getFullYear(), args.value.getMonth(), args.value.getDate());
           }
  }

Please note that a ISO 8601 string parsed by js Date() object may have non-zero number of hours due to UTC offset which also may influence comparing dates with “Equals” operator.

To diagnose you can try to verify data using grid’s data() method and compare them to the filter value in the filtering event handler. wijgrid compares dates as numbers returned by date.getTime().

Answer

Tagged: ,

This topic has 2 voices, contains 9 replies, and was last updated by  sergeys 328 days ago.

You must be logged in to reply to this topic.