Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 622
Armance Avatar asked Sep 16 '11 15:09

Armance


Video Answer


1 Answers

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.

like image 187
Armance Avatar answered Oct 16 '22 23:10

Armance