Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Table column filter value type could be number or boolean #22277

Merged
merged 3 commits into from
Mar 18, 2020
Merged

fix: Table column filter value type could be number or boolean #22277

merged 3 commits into from
Mar 18, 2020

Conversation

xudongcc
Copy link

@xudongcc xudongcc commented Mar 16, 2020

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

While using TypeScript, ColumnFilterItem value type of Table is valid only by string.
number and boolean types are used in many cases, so they can be of any type.

📝 Changelog

Language Changelog
🇺🇸 English
🇨🇳 Chinese Table column.filtervalue 定义可以支持 string | number | boolean

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@ant-design-bot
Copy link
Contributor

ant-design-bot commented Mar 16, 2020

@xudongcc
Copy link
Author

Example:

import React from "react";
import { Table } from "antd";
import { ColumnsType } from "antd/lib/table";

interface Order {
  id: string;
  processed: boolean;
  status: number;
}

const columns: ColumnsType<Order> = [
  {
    title: "ID",
    dataIndex: "id"
  },
  {
    title: "Processed",
    dataIndex: "processed",
    filters: [
      { text: "Yes", value: true },
      { text: "No", value: false }
    ],
    render: value => `${value}`,
    onFilter: (value, record) => record.processed === value
  },
  {
    title: "Status",
    dataIndex: "status",
    filters: [
      { text: "Created", value: 0 },
      { text: "Approved", value: 1 },
      { text: "Completed", value: 2 }
    ],
    onFilter: (value, record) => record.status === value
  }
];

const orders: Order[] = [
  {
    id: "1001",
    processed: true,
    status: 0
  },
  {
    id: "1002",
    processed: false,
    status: 1
  },
  {
    id: "1003",
    processed: false,
    status: 2
  }
];

function App() {
  return <Table<Order> columns={columns} dataSource={orders} />;
}

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 16, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b159470:

Sandbox Source
antd reproduction template Configuration

@codecov
Copy link

codecov bot commented Mar 16, 2020

Codecov Report

Merging #22277 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #22277      +/-   ##
==========================================
+ Coverage   97.96%   97.96%   +<.01%     
==========================================
  Files         306      306              
  Lines        7043     7044       +1     
  Branches     1938     1893      -45     
==========================================
+ Hits         6900     6901       +1     
  Misses        143      143
Impacted Files Coverage Δ
...omponents/table/hooks/useFilter/FilterDropdown.tsx 95.94% <100%> (+0.05%) ⬆️
components/table/hooks/useFilter/index.tsx 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 23f5e3e...b159470. Read the comment docs.

Co-Authored-By: 偏右 <afc163@gmail.com>
@afc163
Copy link
Member

afc163 commented Mar 17, 2020

检查一下 ci,看看什么问题。

@afc163 afc163 merged commit 8fb9db1 into ant-design:master Mar 18, 2020
@afc163 afc163 changed the title fix: Table column filter value type could be any fix: Table column filter value type could be number or boolean Mar 18, 2020
@xudongcc xudongcc deleted the fix-table-column-filter-value-type branch March 19, 2020 08:38
@li-jia-nan li-jia-nan mentioned this pull request Feb 2, 2023
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants