Armance
Armance

Reputation: 5390

How to set default sort column in extjs4 grid and change date format?

1-How do I set the column to be sorted when the grid is created? then upon reloading the grid, it automatically utilize that sort to appropriately display the records.(without me clicing on it) Can this be done on the grid itself so it is independent of the underlying data store?

2-how do i change Date format displaying in a grid column? my data render a date like this /Date(1316020760837+0000)/ i tried using renderer: Ext.util.Format.dateRenderer('m/d/Y'),// format: 'm d Y' but it gives me NaN/NaN/NaN

any help would be appreciated. thank you

Upvotes: 6

Views: 12533

Answers (1)

Armance
Armance

Reputation: 5390

solved:

  1. i used sortOnLoad with sorters

    var myStore = new Ext.data.JsonStore({
    fields: ['Item1', 'Item2', 'Item3', 'Item4'] 
    , data: []
    , sortOnLoad: true
    , sorters: { property: 'Item1', direction : 'DESC' }
    });
    
  2. in my c# code i used item.DateEnd.ToString("MMM dd, yyyy"). see this or this for standard and custom format

or better in extjs4 ,you should specify the dateFormat so Ext can parse it properly and you'll ensure it gets read ok.

   {name: 'Item1' , type : 'date',dateFormat :'MS'}

u can see this for available format strings.

Upvotes: 18

Related Questions