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

onFilterChange

Open rayray93 opened this issue 7 years ago • 21 comments

Is there event witch can handle the filter changes?

Im currently set table state in url, for now i can track table state with these handlers.. * onChangePage | func |   | To handle page changes (page) onChangeRowsPerPage | func |   | To handle rows per page changes (pageSize) onOrderChange | func |   | To handle order changes (orderedColumnId, orderDirection) onRowClick | func |   | To handle row click (event, rowData) *

but i also need to set filter params in state but i cant handle changes in them... any suggestions how can i track this event ?

rayray93 avatar Mar 25 '19 15:03 rayray93

Hi @rayray93 ,

Did you see remote data feature? It lets you to manage all events.

https://mbrn.github.io/material-table/#/docz-examples-14-example-remote-data

mbrn avatar Mar 25 '19 18:03 mbrn

@mbrn Thanks u for response :)

Yes, i saw feature but problem is when i navigate away from that table and came back im loosing page, pageSize, filters.. etc.

so i switch to static data, so i fetch(fetching by url) data in array assign it to table data and then handle url by events onPageChange, onSortChange etc but there is no event for filterChange...

so far i get my table state via url when i navigate away and came back but still need that filter params in url..

any suggestion how to handle this? Thanks

rayray93 avatar Mar 27 '19 08:03 rayray93

I got your requirement. I will add this event asap.

As a workaround you can do this:

 <MaterialTable
                components={{
                  Body: props => <MTableBody {...props} onFilterChanged={(columnId, value) => {
                    props.onFilterChanged(columnId, value);
                    // Do you job here :)
                  }}/>
                }}
.....
              />

mbrn avatar Mar 27 '19 10:03 mbrn

How do you implement a debounce in this situation? when is trigger this function is after the debounce ?

Best Regards

orestesparra avatar Mar 27 '19 13:03 orestesparra

This is a workaround. so in this solution i avoid the debounce.

mbrn avatar Mar 27 '19 13:03 mbrn

customFilterAndSearch have a debounce ?

orestesparra avatar Mar 27 '19 13:03 orestesparra

yes, table calls customFilterAndSearch in a debounce.

mbrn avatar Mar 27 '19 16:03 mbrn

Hi, I tried your workaround as in here: import MTableBody from 'material-table'; .... <MaterialTable components={{ Body: props => <MTableBody {...props} onFilterChanged={(columnId, value) => { props.onFilterChanged(columnId, value); // Do you job here :) }}/> }}

but the page won't render, in hanging stage. Any idea?
Another question, how soon do you think you will have a release for this feature?

Thanks much in advance.

mkong66 avatar Apr 01 '19 19:04 mkong66

use this:

import MaterialTable, { MTableBody} from 'material-table';

After resolving a few issues i will publish a new release. It generally takes a few days. But nowadays i am very busy. I hope that i will publish a new release asap.

mbrn avatar Apr 01 '19 19:04 mbrn

sorry about the stupid questions, I am pretty new to react.
I have this error Uncaught TypeError: Cannot read property 'paging' of undefined, at MTableBody.render.... And quick pointer is much appreciated.

mkong66 avatar Apr 01 '19 19:04 mkong66

No problem @rayray93 ,

Did you use this?

{...props}

mbrn avatar Apr 01 '19 20:04 mbrn

Yes, exactly as here: <MaterialTable components={{ Body: props => <MTableBody {...props} onFilterChanged={(columnId, value) => { props.onFilterChanged(columnId, value); // Do you job here :) }}/> }}

mkong66 avatar Apr 01 '19 20:04 mkong66

components={{
         Toolbar: props => <MTableBody {...props} onFilterChanged={(columnId, value) => {
                props.onFilterChanged(columnId, value);
                                // Do you job here :)
                            }}/>
                        }}

                        options={{
                            pageSize:10,
                            paging:false,
                            exportButton:true,
                            columnsButton:true,
                            pageSizeOptions:[10,20,30],
                            actionsColumnIndex: -1,
                            rowStyle:{height:"20px"},
                            maxBodyHeight: 700,
                            filtering:true,
                        }}

I have the paging prop specified above, have no idea why it won't pass, with this error msg: bundle.js:82021 Uncaught TypeError: Cannot read property 'paging' of undefined

Any idea? Thanks.

mkong66 avatar Apr 02 '19 01:04 mkong66

components={{ Toolbar: props => <MTableBody options={{ pageSize:10, paging:false, }} {...props} onFilterChanged={(columnId, value) => { props.onFilterChanged(columnId, value); debugger // Do you job here :) }} /> }}

Got a little closer by moving options inside of Toolbar component, now I got error: Uncaught TypeError: _this2.props.getFieldValue is not a function

mkong66 avatar Apr 02 '19 03:04 mkong66

No. This is not a good solutions. props should contain these fields. Can you check props please? Rename it to avoid name conflicts

mbrn avatar Apr 02 '19 05:04 mbrn

@mbrn Why did you close this? Did you implement this already? Otherwise I would be ready to open a MR.

a544jh avatar Jun 13 '19 13:06 a544jh

Hi @a544jh

Hi, I tried your workaround as in here: import MTableBody from 'material-table'; .... <MaterialTable components={{ Body: props => <MTableBody {...props} onFilterChanged={(columnId, value) => { props.onFilterChanged(columnId, value); // Do you job here :) }}/> }}

but the page won't render, in hanging stage. Any idea? Another question, how soon do you think you will have a release for this feature?

Thanks much in advance.

I think this is a solution for this case.

mbrn avatar Jun 14 '19 05:06 mbrn

@mbrn Hi Sir, I start working with meterial-table and i found it great. Thanks for your work but i facing issue while using onOrderChange prop. This call back is not working and not showing any data of orderBy and orderDirection. if i got it right is this handle event of drag column position and one thing more please give a prop for custom ordering and selection of columns in your next Update. thanks in advance

ghost avatar Jul 02 '19 14:07 ghost

@mbrn - I'm trying to use your workaround with the custom Body component onFilterChanged behavior. I'm running into an issue though when trying to set state on my component in the event handler. Using a hook or a redux action causes the table to 'reset'? I type a filter and the event is handled, but as soon as the call is made that reaches out of the scope of the handler, the table clears.

here's my code:

components={{
    Body: bodyProps => (
	<MTableBody
		{...bodyProps}
		onFilterChanged={(columnId: number, value: string) => {
			// get column's fieldName
                        // get data whose prop has same value as filter

                        // redux action, tried using local hook for state as well
			props.setSummaryData(matchingRows); 

			bodyProps.onFilterChanged(columnId, value);
		}}
/>),
}}

and here's the behavior I'm seeing: filter-issue

seanmccay avatar Oct 25 '19 15:10 seanmccay

I'm gonna put this on an open issue

seanmccay avatar Oct 25 '19 15:10 seanmccay