Added new feture in sortTable turboTable

UI Components for Angular
Post Reply
magliarov
Posts: 5
Joined: 12 Apr 2018, 13:38

23 Apr 2018, 23:04

Hello

I had the need to use multisort + customsort in order to sort in a turbotable several fields included one that contains cells with object values like {value: xyz} (output of a dropdown selection).
Beacuse of the feature of custom sort doesn't work if multisort is turned on, I've directly modified the multisort method in turbotable code adding the following lines:

Code: Select all

   Table.prototype.multisortField = function (data1, data2, multiSortMeta, index) {
        var value1 = this.objectUtils.resolveFieldData(data1, multiSortMeta[index].field);
        var value2 = this.objectUtils.resolveFieldData(data2, multiSortMeta[index].field);
        var result = null;
        if (typeof value1 == 'string' || value1 instanceof String) {
            if (value1.localeCompare && (value1 != value2)) {
                return (multiSortMeta[index].order * value1.localeCompare(value2));
            }
		//START EDITED CODE
		}
		else if (Object.prototype.toString.call(value1) === '[object Object]' && Object.prototype.toString.call(value2) === '[object Object]'){
			result = (value1.value<value2.value)?-1: (value1.value >value2.value)?1:0;
			return (multiSortMeta[index].order * result);
		//END EDITED CODE
		}
        else {
            result = (value1 < value2) ? -1 : 1;
        }
        if (value1 == value2) {
            return (multiSortMeta.length - 1) > (index) ? (this.multisortField(data1, data2, multiSortMeta, index + 1)) : 0;
        }
        return (multiSortMeta[index].order * result);
    };
    
Could be helpful for someone if this piece of code would be added to the library?

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests