material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Specify totalCount without remote data

Open m5tt opened this issue 7 years ago • 8 comments

We are handling our data fetching & paginating manually (through Redux) and passing it to MaterialTable without a promise:

<MaterialTable
  ...
  title='Members'
  data={props.members}
/>

However, it appears that MaterialTable gets the total count from this array and doesn't let us specify.

This issue had the same problem, and remoteData was added to allow the user to specify the totalCount, through a Promise.

However we have zero need for using a Promise, and would like to pass totalCount straight to MaterialTable. Additionally a Promise doesn't work for us either, because the data is empty on the first render, and MaterialTable does not re call the Promise on data change.

For example, this could be implemented in multiple ways:

Passing it as a normal prop:

<MaterialTable
  ...
  title='Members'
  data={props.members}
  totalCount={props.memberCount}
/>

or formatting data as an object, ie the object that Promise is supposed to return:

<MaterialTable
  ...
  title='Members'
  data={ { data: props.members, totalCount: props.memberCount, page: 0}
/>

m5tt avatar Aug 12 '19 23:08 m5tt

i have the exec same question, if it is possible to give data as array as specified, ( data | Array or func for remote data ) how do i give the total count?

tried also on pagination and didn't work pagination:{ labelRowsPerPage: this.state.rowsPerPage, page:page, totalCount:totalCount }

ruthwe avatar Aug 13 '19 09:08 ruthwe

Using remote data will also not work with Apollo as it will just go into infinite loop. Prefer to pass totalCount through options.

devopsjosh avatar Aug 23 '19 15:08 devopsjosh

Hi there,

I was dealing with the same issue and I finally managed to overwrite de Pagination component and handle the events on my Container so I can dispatch redux actions.

I works well so far.

I used this component: https://material-ui.com/api/table-pagination/ and found about component overwriting here: https://material-table.com/#/docs/features/component-overriding

Hope it helps someone.

Cheers

domingueznoda avatar Dec 08 '19 18:12 domingueznoda

It seems to be resolved by https://github.com/mbrn/material-table/pull/795.

FujiHaruka avatar Mar 21 '20 12:03 FujiHaruka

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You can reopen it if it required.

stale[bot] avatar Jul 05 '20 19:07 stale[bot]

Can you help me with how to use totalCount with remote data?

anmol5varma avatar Sep 10 '20 00:09 anmol5varma

It seems to be resolved by #795.

Yes, it works, but not described in the documentation. Just specify simultaneously 2 props:

  • page (current page)
  • totalCount
            <MaterialTable
              ...
              data={data}
              page={page}
              totalCount={count}
              ... 
            />

azakharo avatar Dec 12 '20 04:12 azakharo

It seems to be resolved by #795.

Yes, it works, but not described in the documentation. Just specify simultaneously 2 props:

  • page (current page)
  • totalCount
            <MaterialTable
              ...
              data={data}
              page={page}
              totalCount={count}
              ... 
            />

This worked for me. Thanks!

ejrekruit avatar Apr 06 '21 17:04 ejrekruit