Skip to content

Setting rows per page and default sort id based on prop #1268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Soham-SoftCorner opened this issue Dec 23, 2024 · 0 comments
Open

Setting rows per page and default sort id based on prop #1268

Soham-SoftCorner opened this issue Dec 23, 2024 · 0 comments

Comments

@Soham-SoftCorner
Copy link

Describe the bug

The change in the value of defaultSortFieldId and paginationPerPage is not reflected when it is set externally.

To Reproduce

Steps to reproduce the behavior:
Render a table. Pass a getter of a hook to paginationPerPage and defaultSortFieldId. Add a null check.
Now set the value of the prop in the use effect that runs on a page load. The updated value is not reflected in the table. The change is only reflected when sort icon is clicked or paginationPerChange is set from the ui.

Expected behavior

The table should rerender when the prop value changes. (Even when set from the code and not ui)

Code Sandbox, Screenshots, or Relevant Code

In this code, the state of pagination and sorting is restored from redux and then the state is updated.
const reStoreReduxState = (reduxKey: string) => {

if(reduxKey != '' && reportList.length > 0){
  const state = reduxObj[reduxKey] || null;
  AppUtility.clearNavDetailsObjectWithKey(reduxKey);
  if(state){
    setPaginationState((prevState) => state?.paginationParams ?? prevState);
    setSortingState((prevState) => state?.sortingParams ?? prevState);
    // setPageState((prevState) => state ?? prevState)
  }
}

}
<DataTable

        columns={columns}
        data={data}
        pagination
        paginationDefaultPage={paginationState?.pageNo ?? 1}
        paginationPerPage={paginationState?.rowsPerPage ?? 10}
        onChangePage={handlePaginationPageChange}
        onChangeRowsPerPage={handleRowsPerPage}
        defaultSortFieldId={sortingState?.sortField ?? 1}

        defaultSortAsc={sortingState?.sortOrder == SortOrder.asc  || false}
        onSort={(column, direction) => {handleSortChange(column.id,direction)}}
      
      />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant