Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

column sorting for ag-grid not working

I have an ag-grid and I am dynamically loading data into it. I have enabled column sorting, however it does not work. Nothing happens when I click on the column header. I'm not sure what the issue is. Below is my code:

    var colobj = {};
    for(i = 0; i< file.fieldMetadata.length; i++){

   var len = file.fieldMetadata[i].name.length;

   colobj = {'headerName' : file.fieldMetadata[i].name, 'field' : file.fieldMetadata[i].name, sortingOrder: ['asc','desc', 'null']};

vm.columnDefs.push(colobj);

    vm.gridOptions.api.setColumnDefs(vm.columnDefs);
    vm.gridOptions.api.setRowData(vm.fileContentsCols);
    vm.gridOptions.enableSorting = true;
like image 467
Vedant Nighojkar Avatar asked Mar 13 '23 16:03

Vedant Nighojkar


1 Answers

The enableSorting won't work here. Only call to api function will work.

You have to set gridOptions.enableSorting = true from the beginning (not after receive the data).

The gridOptions is merely a holder for initialisation. Once the grid is initialise, the api field is available to interact with the grid, all change to parameters won't work.

like image 133
Walfrat Avatar answered Mar 23 '23 07:03

Walfrat