Search code examples
vue.jsprimevue

PrimeVue v3.17: Datatable: Reset sort to default sortField


    const defaultSort = {
      field: "column1",
      sortOrder: 1,
    };
<DataTable
        id="table_searchResults"
        :value="searchResults"
        :paginator="true"
        :rows="defaultRowsPerPage"
        paginatorTemplate="Rows per page: RowsPerPageDropdown FirstPageLink PrevPageLink CurrentPageReport NextPageLink LastPageLink"
        :rowsPerPageOptions="rowsPerPage"
        currentPageReportTemplate="{currentPage} of {totalPages}"
        :sortField="defaultSort.field"
        :sortOrder="defaultSort.sortOrder"
        lazy
        :totalRecords="totalElements"
      ></DataTable>

Lazy datatable with default sort. After doing sort on another column, performing search is not resetting the table to default sort column.

Any thoughts?


Solution

  • Define a ref value for your table and use it to set the sort field and order.

    tableRefValue.value.d_sortField = defaultSort.field;
    tableRefValue.value.d_sortOrder = defaultSort.sortOrder;