ng2-table icon indicating copy to clipboard operation
ng2-table copied to clipboard

Sorting issue

Open mksasi opened this issue 10 years ago • 9 comments

There is a issue in sorting when navigating to descending. The issue is in the file ng2-table/components/table/ng-table-sorting.directive.ts line 28: this.column.sort = '';

It works when its changed to this.column.sort = 'asc'; Can this fix be added soon.

Sasi

mksasi avatar May 21 '16 07:05 mksasi

I don't think they see this as an issue. As far as I understood, When it's ascending and you click the column, it changes to descending. When it's descending and you click it, it returns to the default order of the list...(even if the default it's no order...). And then you click again, it changes to ascending again... I think it's actually 3 different status: 1. No order/default order as it is in the array, 2. ascending 3. descending. I'm not saying this is good though... I actually changed my code as you suggested, so this "No order" status doesn't exists anymore...

raquelleira avatar Jul 24 '16 23:07 raquelleira

Many Thanks. Can you please push this change to the master branch?

mksasi avatar Jul 25 '16 04:07 mksasi

@raquelleira could you please check out #335? Is it possible to change the sorting so that step (1) is disabled completely?

ghost avatar Oct 26 '16 20:10 ghost

@raquelleira How to disable the 3rd click in ng2-table/demo/components/table/table-demo.ts file? Plese suggest

protagonist51 avatar Jan 12 '17 20:01 protagonist51

You can customize component as below.

ng2-table/components/table/ng-table-sorting.directive.js line:17

Then you can see these code

    NgTableSortingDirective.prototype.onToggleSort = function (event) {
        if (event) {
            event.preventDefault();
        }
        if (this.ngTableSorting && this.column && this.column.sort !== false) {
            switch (this.column.sort) {
                case 'asc':
                    this.column.sort = 'desc';
                    break;
                case 'desc':
                    this.column.sort = '';
                    break;
                default:
                    this.column.sort = 'asc';
                    break;
            }
            this.sortChanged.emit(this.column);
        }
    };

This is code for switching sorting mode. If you change this as below then you can use only two methods.

    NgTableSortingDirective.prototype.onToggleSort = function (event) {
        if (event) {
            event.preventDefault();
        }
        if (this.ngTableSorting && this.column && this.column.sort !== false) {
            switch (this.column.sort) {
                case 'asc':
                    this.column.sort = 'desc';
                    break;
                case 'desc':
                    this.column.sort = 'asc';
                    break;
                default:
                    this.column.sort = 'asc';
                    break;
            }
            this.sortChanged.emit(this.column);
        }
    };

You can fort repository and use component as freely :)

webcat12345 avatar Jan 13 '17 04:01 webcat12345

@webcat12345 You are awesome!!!

protagonist51 avatar Jan 13 '17 07:01 protagonist51

@webcat12345 Is it possible to override this functionality in the file table-demo.ts of ng2-table/demo/components/table/?? I want to have only 2 way sorting in the implementation level and this is in module level. I mean if someone wants to implement my project, he will do an "npm install ng2-table" and he has to change the below code manually case 'desc': this.column.sort = 'asc'; break; So is it possible to customize this in our own code which implements ng2-table?

Thanks

protagonist51 avatar Jan 14 '17 06:01 protagonist51

@webcat12345 Any solution for the above problem?

protagonist51 avatar Jan 19 '17 05:01 protagonist51

Currently there is no other way. But you can fork this repository and can make changes to component

webcat12345 avatar Jan 19 '17 08:01 webcat12345