【问题标题】:Set pagination on MaterialTable ui https://material-table.com/#/docs/features/localization?在 MaterialTable ui https://material-table.com/#/docs/features/localization 上设置分页?
【发布时间】:2020-04-01 07:36:36
【问题描述】:

这是我的代码。我想将分页设置为每页 50、100、250 行(例如)。我怎样才能做到这一点?

 <MaterialTable

        localization={{
          pagination: {
            labelDisplayedRows: '4-6 of 10',
            labelRowsPerPage:'{5, 10, 25,100}'
          },

        }}
        title="Crawler Results"
        columns={[
          { title: "URL", field: "url" },
          { title: "Status", field: "status" }
        ]}
        data={state.data}
        actions={[
          {
            icon: 'add',
            tooltip: 'Add User',
            isFreeAction: true,
            onClick: () => {

              //show crawler table and hide formular
              document.getElementById('formCrawler').style.display = "block";
              document.getElementById('formSpan').style.display = "block";
              document.getElementById('crawlerTableID').style.display = "none";

            }
          }]}
      />

【问题讨论】:

    标签: reactjs pagination material-ui material-table


    【解决方案1】:

    添加labelRowsPerPage 对我没有任何帮助。我在MaterialTable 中添加了以下属性:

    options={{
      pageSizeOptions: [50, 100, 250]
    }}
    

    https://material-table.com/#/docs/all-props

    【讨论】:

      【解决方案2】:

      docs 中所述,您可以使用一组页面大小覆盖options 中的pageSizeOptions

      <MaterialTable
      
          localization={{
            pagination: {
              labelDisplayedRows: '4-6 of 10',
              labelRowsPerPage:'{5, 10, 25,100}'
            },
      
          }}
          title="Crawler Results"
          columns={[
            { title: "URL", field: "url" },
            { title: "Status", field: "status" }
          ]}
          options={{
              pageSizeOptions : [50, 100, 200]
          }}
          data={state.data}
          actions={[
            {
              icon: 'add',
              tooltip: 'Add User',
              isFreeAction: true,
              onClick: () => {
      
                //show crawler table and hide formular
                document.getElementById('formCrawler').style.display = "block";
                document.getElementById('formSpan').style.display = "block";
                document.getElementById('crawlerTableID').style.display = "none";
      
              }
            }]}
        />
      

      【讨论】:

      • 谢谢它帮助了我,我在这个问题上花了大约一个小时
      • 很高兴我能提供帮助,如果这解决了您的问题,您能否将答案标记为已接受,以便其他人可以找到它?
      猜你喜欢
      • 2020-04-30
      • 2021-03-16
      • 2021-01-03
      • 1970-01-01
      • 2016-06-10
      • 1970-01-01
      • 2021-01-29
      • 2021-01-27
      • 2019-05-20
      相关资源
      最近更新 更多