English 中文(简体)
why custom filter reset button is not working for antd filterdropdown in table?
原标题:

I have this custom filter for date , filter button is working as expected but reset button is not working, can anyone help me,what s wrong here?

Below is my code which contain handlesearch,handlereset functions and all the props that is passed in the columns.So for clearing the filter i am using clearFilters method which we get from filterDropdown. But i am not able to reset the filter.

const handleSearch = (selectedKeys, confirm, dataIndex) => {
    console.log(selectedKeys, confirm, dataIndex)
    confirm()
  }

  const handleReset = (clearFilters, dataIndex) => {
    console.log(clearFilters)
    clearFilters()
  }
  const getColumnSearchProps = (dataIndex) => ({
    filterDropdown: ({
      setSelectedKeys,
      selectedKeys,
      confirm,
      clearFilters,
    }) => (
      <div style={{ padding: 8 }}>
        <Form form={form}>
          <DatePicker
            format={ DD-MMM-YYYY }
            onChange={(e) => {
              setSelectedKeys([e.format( DD-MMM-YYYY )])
            }}
            allowClear={false}
          />

          <Button
            type="primary"
            onClick={() => handleSearch(selectedKeys, confirm, dataIndex)}
            icon={<Filter />}
            htmlType="submit"
            size="small"
            style={{ width: 90 }}
          ></Button>
          <Button
            type="primary"
            onClick={() => handleReset(clearFilters, dataIndex)}
            size="small"
            icon={<Filter />}
            style={{ width: 90 }}
          >
            Reset
          </Button>
        </Form>
      </div>
    ),
    filterIcon: (filtered) => (
      <Filter style={{ color: filtered ?  #1890ff  : undefined }} />
    ),
    onFilter: (value, record) => {
      return moment(record[dataIndex]).format( DD-MMM-YYYY ) === value
    },

   
   
  })

问题回答

Can you try put confirm() in handleReset function.

const handleReset = (clearFilters,confirm, dataIndex) => {
      console.log(clearFilters)
      clearFilters()
      confirm()
}

This will trigger props onChange in component Table ANTD





相关问题
How do I reset or override IE CSS filters?

I m using the proprietry MS filter property to try and create a non ugly equivalent to css3 text-shadow and box-shadow; I was actually doing really well until I hit this problem. It looks like when ...

PHP filter string input, cut off all newlines, 1 chars

I m writing in PHP! There s a user string input, and I want to cut off all newlines,1 chars that are more than 1 in a row (avoid <br /><br />...). example: I am a SPaMmEr! would ...

The Fastest DataStructure to Filter with in C#

Currently we are filtering and sorting data with a datatable. /// <summary> /// Filters the data table and returns a new data table with only the filtered rows. /// </summary>...

How to dynamically update a ListView on Android [closed]

On Android, how can I a ListView that filters based on user input, where the items shown are updated dynamically based on the TextView value? I m looking for something like this: -------------------...

Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Best method to scale DropShadows in AS3?

I m creating a flash application that makes use of both the dropShadow filter and scaling of various sprites. And therein lies the problem: This filter supports Stage scaling. However, it does ...

热门标签