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

Search is not working at Remote data code

Open PATTANPARVIN opened this issue 6 years ago • 10 comments

Search is not working while calling rest call dynamically

PATTANPARVIN avatar Dec 11 '19 05:12 PATTANPARVIN

I have search working fine with a dynamic REST (actually GraphQL, but still remote) can you share a code snippet?

cbschuld avatar Dec 17 '19 23:12 cbschuld

@cbschuld are you using onSearchChange with material-table 1.54.2 ?

szkiecin avatar Dec 19 '19 09:12 szkiecin

i have the same issue, the documentation example not working too. https://material-table.com/#/docs/features/remote-data

tuliocll avatar Dec 22 '19 19:12 tuliocll

@cbschuld can you share your implementation of remote search ?

gaurav-agarwal27 avatar Jan 02 '20 06:01 gaurav-agarwal27

i have the same issue, the documentation example not working too. https://material-table.com/#/docs/features/remote-data

facing same issue . have you got solution?

narottamdattatrey avatar Jan 06 '20 07:01 narottamdattatrey

Search is not working while calling rest call dynamically

simply first save your api data into variable instead of fetching directly from an api into MaterialTable data. then add that variable data into materialTable data. Capture

therohitjha avatar Jan 17 '20 11:01 therohitjha

hello,I solve this problem use

function handlePagingQuery(query) {
    if(query.search){
      return new Promise(resolve => {
        axios.get(`${api}?search=${query.search}`).then(res => {
          resolve(res)
        })
      })
    }else{
       // fetch your initial data
    }
  
  }
  return (
    <MaterialTable
      data={handlePagingQuery}
    />
  );

hope this will help you

joshuap233 avatar Jan 19 '20 09:01 joshuap233

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 Jun 30 '20 22:06 stale[bot]

This worked for me.

      <MaterialTable        
        title="Refresh Data Preview"
        tableRef={tableRef}
        columns={[
          { title: 'Id', field: 'id' },
          { title: 'First Name', field: 'object_id' },
          { title: 'Last Name', field: 'last_name' },
        ]}
        data={query =>
          new Promise((resolve, reject) => {

            if(query.search){
                console.log(query.search)

                fetch( `${props.route}?filter=${query.search}` )
                .then(response => response.json())
                .then(result => {
                  console.log(result)
                  resolve({
                    data: result.data,
                    page: result.page - 1,
                    totalCount: result.total,
                  })
                })

              }else{

                let url = props.route
                url += '?per_page=' + query.pageSize
                url += '&page=' + (query.page + 1)
                fetch(url)
                  .then(response => response.json())
                  .then(result => {
                    console.log(result)
                    resolve({
                      data: result.data,
                      page: result.page - 1,
                      totalCount: result.total,
                    })
                  })
              }
            })
        }
        actions={[
          {
            icon: 'refresh',
            tooltip: 'Refresh Data',
            isFreeAction: true,
            onClick: () => tableRef.current && tableRef.current.onQueryChange(),
          }
        ]}
        options={{
            search: true
          }}
      />

ghost avatar Jul 10 '20 01:07 ghost

I have search working fine with a dynamic REST (actually GraphQL, but still remote) can you share a code snippet?

https://material-table.com/#/docs/features/remote-data This is the example from documentation where search doesn't work. how did you overcome the issue ? Thanks

AravindTReddy avatar Jun 04 '21 04:06 AravindTReddy