Search code examples
reactjsreact-reduxmaterial-uimaterial-table

Textfield Values missing while searching


My textfield values go missing when I search for keywords that match that particular field. Posting full code of my materialtable library used.

<MaterialTable
    columns={[
        { title: 'Customer Name', field: 'custName', editable: 'never' },
        { title: 'Order Amount', field: 'orderAmount', render: rowData => 
            <TextField
                size="small"
                required
                onChange={e => {
                    this.props.getUpdatedOrderAmount(e.target.value, rowData)}
                }
                value={this.state.value}
            />
        }
    ]}
    data={data}
/>

Solution

  • For searching use cell's property customFilterAndSearch like:

    { title: 'Full name', searchable: true, 
      customFilterAndSearch: (filter: any, rowData: any, columnDef: any): boolean => {
        const s = (rowData.firstName + ' ' + rowData.lastName).toLocaleLowerCase();
        return s.indexOf(filter.toLocaleLowerCase()) >= 0;
      },
      render: rowData => rowData.firstName + ' ' + rowData.lastName
    },