Describe the bug
Using column with custom render function exclude it from search.
To Reproduce
Steps to reproduce the behavior:
render for idExpected behavior
Search results show columns with matching id
Actual behaviour
Search cant use columns with render
Additional context
E.g. columns
const columns = [
{title: 'Some Id', render: renderSomeId, field: 'some_id'},
...
];
...
const renderSomeId = (row) => {
<Link to={someUrl + row.some_id}>
{row.some_id}
</Link>
}
As a result, we have links with id text shown. If we have ids like abc123, abc234, test000 we would expect that search for abc would show first 2 rows; however, "no results" shown.
Hi @DmitryNefedov,
I will do this feature asap
@DmitryNefedov ,
I change search to run on field value of every column. Not on render result. Because render result is a React.Element and it is not searchable. if you want to make a column that has custom render method searchable, you should specify the field for it
If you have any trouble or requirement please feel comfort to ask me?
@mbrn how I can make custom rendered field searchable?
@sarates ,
Add customFilterAndSearch field to your column definition.
customFilterAndSearch: (value, rowData) => {
return true; // customize here according your search algorithm.
}
@mbrn thanks a lot!
@mbrn Can you please insert some example code of customFilterAndSearch, I'm not understanding how to use this function
Hi @Prasad-YS ,
I think that would be enough for you
<MaterialTable
columns={[
{
title: 'Name',
render: rowData => rowData.name + ' ' + rowData.surname,
customFilterAndSearch: (term, rowData) => (rowData.name + ' ' + rowData.surname).indexOf(term) != -1
},
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: '陌stanbul', 63: '艦anl谋urfa' },
}
]}
data={[
{
name: 'Mehmet',
surname: 'Baran',
birthYear: 1987,
birthCity: 63
},
{
name: 'Zerya Bet眉l',
surname: 'Baran',
birthYear: 2017,
birthCity: 34
},
]}
title="Custom Render"
/>
Hi @Prasad-YS ,
I think that would be enough for you
<MaterialTable columns={[ { title: 'Name', render: rowData => rowData.name + ' ' + rowData.surname, customFilterAndSearch: (term, rowData) => (rowData.name + ' ' + rowData.surname).indexOf(term) != -1 }, { title: 'Birth Year', field: 'birthYear', type: 'numeric' }, { title: 'Birth Place', field: 'birthCity', lookup: { 34: '陌stanbul', 63: '艦anl谋urfa' }, } ]} data={[ { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 }, { name: 'Zerya Bet眉l', surname: 'Baran', birthYear: 2017, birthCity: 34 }, ]} title="Custom Render" />
Thanks a lot
I know it is close this, but I need Help
the filter box dont appear for me if I dont write field:
so I dont understand how you can made a filter with this customFilterAndSearch if the box dont appear
Best Regards
You are right @orestes22
It is a bug. I fixed it. I will publish it asap.
Still not working. If you dont have Field with something between "" , it isnt works.
Also I would like add in the Filter a Selection of checkbox with the option that appear in the colums. Can I implement that in the customFilterAndSearch ?
Best Regards
you should have field or customFilterAndSearch in column definition. Can you check it again please?
In your example works , but in my code doesnt, Im not sure why, because I check your code and you only have and "if" for show or not show that. but this is a minor things.
What comment do you have for this:
I would like add in the Filter a Selection of checkbox. Can I implement that in the customFilterAndSearch ?
I would like that people choose the word and after that I will filter using that
You can do this by customFilterAndSearch .
Most helpful comment
Hi @Prasad-YS ,
I think that would be enough for you