Manually multi sorting using ngx-mat-multi-sort

Discussão em 'Angular' iniciado por npankaj, Janeiro 28, 2025.

  1. npankaj

    npankaj Guest

    Trying to set predefined columns and directions and below code is not working so any one can check and suggest what

    public table: TableData<any> = new TableData<any>([], {});
    @ViewChild(MatMultiSort, { static: false }) sort: MatMultiSort;


    InitializeSortParams(reportData: any) {
    this.table.columns = Object.keys(reportData[0]).map((col: any) => ({
    id: col,
    name: col
    }));
    this.table.displayedColumns = Object.keys(reportData[0]);
    if(layoutSortFields)
    {
    let sortObj = this.parseSortString(layoutSortFields);
    sortObj.columns.forEach((element,index) => {
    this.sort.sort(<MatSortable>({ id: element, start: sortObj.directions[index] }));
    });
    }
    this.table.dataSource = new MatMultiSortTableDataSource(this.sort, false);
    if (layoutSortFields) {
    if (this.table.sortDirs.length > 0 && this.table.sortParams.length > 0) {
    this.table.sortDirs = [];
    this.table.sortParams = [];
    }
    try{
    let sortObj = this.parseSortString(layoutSortFields);
    this.table.sortDirs = sortObj.directions;
    this.table.sortParams = sortObj.columns;

    this.table.updateSortHeaders();
    }
    catch(e){
    }
    }
    this.table.totalElements = this.totalPages;
    this.table.data = reportData;
    }


    I need to set columns and directions manually of TableData and sort and need to update the header so that once data will come each time string will come with columns and sorting order and we need to set in table

    Continue reading...

Compartilhe esta Página