1

    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?

1
  • Naming your variable defaultSort doesn't make it a default value... You have to set the sort column when you want it to be changed. Commented Oct 12, 2022 at 18:42

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

I was having problems mixing the data table sort functionality with custom sorting functions of my own and the issue was that i needed to reset the d_sortField and d_sortOrder values to default before applying my own sorting. This helped me figure out how to do it. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.