Lions Den

The Code and Times of Hanan Schwartzberg

About Hanan | Hanan's CV | Contact Hanan

November 12, 2015

Default sort for ui-grid in Angular JS

Filed under: AngularJS,JavaScript — Tags: , , , — Hanan Schwartzberg @ 6:12 am

The Issue

You want to use the internal sorting for an ui-grid, but want to have it sort by default by a specific column.

What didn’t work

Including

sortInfo: {fields:['Title'],directions:['asc']},

in the grid definition didn’t work because it requires using external sorting.

The Solution

The default sort order isn’t declared on the grid level. It’s declared in the definition of the column itself. For example:

columnDefs: [
    {
       field: 'Title', displayName: 'Title', width: 160,
       sort: { direction: uiGridConstants.ASC, priority: 1 }
    },
    {
       field: 'Description', displayName: 'Description', width: 160
    }
]

1 Comment »

  1. Yeah!Its work fine without any problem.

    Comment by Indhu — December 10, 2016 @ 9:30 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Anti-Spam by WP-SpamShield

Home | Site Design | Banner Design | Code Den | Offsite Posts | Downloads | Photography | About Hanan | Hanan's CV | Contact Hanan
Copyright © 2009 Hanan Schwartzberg. All rights reserved.