When useing the Table component in Ant-desigin, i want to get the filterd data in table after executing the filter function on the dataSource, but i cannot find the way to get it. There is a function called onChange which can only get the filter conditions which can not get the filtered data.
Just add a From To column with a custom render function, and set the responsive property on that column to only show on xs screens. The From and To columns will have the responsive property set to show on md and above.
Simply define a new sorting routine in utils/sorter. js , add it to the Sorter “enum,” and use it in your sorter prop for any column that needs it. You can check out the CodeSandbox for this tutorial to play around with the result.
Rows can be selectable by making first column as a selectable column. You can use rowSelection.type to set selection type. Default is checkbox . selection happens when clicking checkbox by default.
Add a property "hidden" to the column object, then filter it out. Save this answer.
I kinda found a way. The props title
and footer
on the <Table />
component take a function which does provide the filtered data.
<Table
footer={currentPageData => {
console.log(currentPageData); // <-- This is an array of the filtered dataSource.
return null;
}}
/>
Add onChange function to Table(sample code is ts, if you are using js, do a little adjustment. And you can check the debug result: total dataSource size is 54, filtered dataSource size is 40, pagination doesn't impact the result
handleChange = (pagination: any, filters: any, sorter: any, extra: { currentDataSource: Array<any>[] }) => {
console.log('Various parameters', extra.currentDataSource);
this.setState({
filteredInfo: extra['currentDataSource']
});
}
renderTable = (columns: Array<object>, dataSource: Array<any>) => {
return (
<Table
dataSource={dataSource}
columns={columns}
expandedRowRender={(record) => (<Markdown source={record['description']} className="brz-mentor-markdown" />)}
onChange={this.handleChange as any}
/>
)
}
You can easily add onChange
attribute inside <Table/>
. Create a function with 4 params: pagination, filters, sorter, extra
and the data you're looking for is extra.currentDataSource
.
onChange={
(pagination, filters, sorter, extra) => {
console.log(extra.currentDataSource)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With