0

For datatable column sorting, I have following datatable:

<lightning-datatable title="MY ORDERS" data={data} columns={columns} key-field = "SalesDocument" onsort={updateColumnSorting} sorted-by={sortedBy} sorted-direction={sortedDirection} onrowaction={handlePdfAction} hide-checkbox-column>
                                </lightning-datatable>

And in js i have this function:

updateColumnSorting(){
      ///this.sortedBy = event.detail.fieldName;
      //console.log("this is sort by"+this.sortedBy);
      //this.sortedDirection = event.detail.sortDirection;
      console.log('function invoke');
      //this.sortData(this.sortedBy,this.sortedDirection);       
  }

this is columns:

@track columns = [{
    label: "Order",
    fieldName:'SalesDocument',
    type: 'url',typeAttributes: {label: { fieldName: 'SalesDocument' }, target: '_blank'},
    },
    {
    label: "Amount",
    fieldName: 'NetAmount',
    type: 'text',
    },
    {
    label: "Order Date",
    fieldName: 'OrderDate',
    type: 'Date',
    },
    {
    label: "Status",
    fieldName: 'OrderStatus',
    type: 'text',
    },
    {
        label: 'Order Confirmation',
        type: 'button-icon',
        initialWidth: 75,
        typeAttributes: {
            iconName: 'utility:print',
            title: 'Print',
            variant: 'border-filled',
            alternativeText: 'Print'
        }
    }
  ];

But the updateColumnSorting function not invoke when i clicked on column.This is pretty much simple but dont know why its not invoke.

2
  • sortable property should be true for columns on which sorting is required. If property is not set as true then sort function will not be called. Please share columns variable. Jun 9, 2019 at 5:43
  • Sir i edit my question and provide columns..thanks for your valuable response.
    – Satish
    Jun 9, 2019 at 5:48

1 Answer 1

1

sortable property should be true for columns on which sorting is required. If property is not set as true then sort function will not be called.

@track columns = [{
        label: "Order",
        fieldName: 'SalesDocument',
        type: 'url',
        typeAttributes: {
            label: {
                fieldName: 'SalesDocument'
            },
            target: '_blank'
        },
        sortable: true
    },
    {
        label: "Amount",
        fieldName: 'NetAmount',
        type: 'text',
        sortable: true
    },
    {
        label: "Order Date",
        fieldName: 'OrderDate',
        type: 'Date',
        sortable: true
    },
    {
        label: "Status",
        fieldName: 'OrderStatus',
        type: 'text',
        sortable: true
    },
    {
        label: 'Order Confirmation',
        type: 'button-icon',
        initialWidth: 75,
        sortable: true,
        typeAttributes: {
            iconName: 'utility:print',
            title: 'Print',
            variant: 'border-filled',
            alternativeText: 'Print'
        }
    }
];
1
  • Ohh great man! Its works fine now.Thank You so much.
    – Satish
    Jun 9, 2019 at 6:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .