Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 ng2-smart-table sorting

In ng2-smart-table of angular 2 sorting functionality is case sensitive. Are there any options to make sorting table data as case insensitive?

like image 509
Revathi Sekar Avatar asked Nov 08 '17 07:11

Revathi Sekar


1 Answers

Just wanted to throw out if you implement this to make sure you add a : after compareFunction. As shown below...

columns: {
    group_name: {
        title: 'Groupname',
        compareFunction:(direction: any, a: any, b: any) => {
            // Converting strings to lowercase
            let first = typeof a === 'string' ? a.toLowerCase() : a;
            let second = typeof b === 'string' ? b.toLowerCase() : b;

            if (first < second) {
                return -1 * direction;
            }
            if (first > second) {
                return direction;
            }
            return 0;
        }
    }
}
like image 161
Lumix Avatar answered Oct 07 '22 10:10

Lumix