Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

javascript - DataGrid React Material UI RowsCount not updating correctly

i'm trying to do some pagination on my App, so i'm using Material UI's Datagrid compoenet, here is how i'm using it:

{!hasTable && !isLoading
  ? <><h1>Choose a table from DB to start</h1></>
  : <DataGrid
    pagination
    rows={rowsValue}
    columns={colValue}
    page={datagridPage}
    pageSize={datagridPageSize}
    rowCount={datagridRowCount}
    onPageChange={DatagridPageChange}
    onPageSizeChange={handlePageSize}
    paginationMode="server"
  />}

Everything is working fine, except for the RowsCount. I'm Getting RowsCount on the event onPageChange (i've tried in other function that executes before onPageChange, but if no success as well).

So, here is the function:

    const [datagridRowCount, setDataGridRowCount] = useState(0);
    const DatagridPageChange = async (event: any) => {
    setDatagridPage(event.page);
    try {
      setIsLoading(true);
      if (activeFilters.length > 0) {
        const response = await countFilterFunction(value, activeFilters, columnsAliasandName);
        setDatagridRowCount(response.data);
      } else {
        const response = await countFilterFunction(value, 0, columnsAliasandName);
        setDatagridRowCount(response.data);
      }
    } catch (error) {
      console.log(error);
    } finally {
      setIsLoading(false);
    };
};

so, normally this method don't work and the material ui automatically giver the rowNumber the numbers of rows of rowsValue.

So, what I'm missing, am i being clear enough?

Thanks.

question from:https://stackoverflow.com/questions/66063904/datagrid-react-material-ui-rowscount-not-updating-correctly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...