Cột ẩn bảng phản ứng-bootstrap
// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';9 tách cơ sở mã lõi bộ lọc thành import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />0, vì vậy sẽ có một chút khác biệt khi bạn sử dụng bộ lọc cột so với import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />1. Trong phần sau đây, chúng tôi sẽ hướng dẫn bạn cách bật bộ lọc cột Show Bản demo trực tiếp cho bộ lọc cột Định nghĩa đạo cụ API Cài đặt$ npm install react-bootstrap-table2-filter --save Bạn có thể nhận tất cả các loại bộ lọc thông qua nhập và các bộ lọc này là một chức năng xuất xưởng để tạo một phiên bản bộ lọc riêng lẻ. Hiện tại, chúng tôi hỗ trợ các bộ lọc sau
Thêm CSS// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'; Bộ lọc văn bảnSau đây là demo nhanh kích hoạt bộ lọc cột trên cột Giá sản phẩm import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } /> Ngoài ra, chúng tôi giữ nguyên tất cả các tính năng và chức năng của bộ lọc trong import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />1 cũ, nhưng theo cách khác để thực hiện import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit... Chọn bộ lọcMột ví dụ nhanh ________số 8_______ Sau đây là một ví dụ cho bộ lọc chọn tùy chỉnh import filterFactory, { selectFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const qualityFilter = selectFilter({ options: selectOptions, placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: '2', // default filtering value comparator: Comparator.LIKE, // default is Comparator.EQ style: { .. }, // your custom styles on input withoutEmptyOption: true // hide the default select option id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...
Mảng dưới dạng tùy chọnconst selectOptions = [ { value: 0, label: 'good' }, { value: 1, label: 'Bad' }, { value: 2, label: 'unknown' } ]; const columns = [ ..., { dataField: 'quality', text: 'Product Quailty', formatter: cell => selectOptions.find(opt => opt.value === cell).label, filter: selectFilter({ options: selectOptions }) }]; Chức năng như tùy chọnconst selectOptions = [ { value: 0, label: 'good' }, { value: 1, label: 'Bad' }, { value: 2, label: 'unknown' } ]; const columns = [ ..., { dataField: 'quality', text: 'Product Quailty', formatter: cell => selectOptions.find(opt => opt.value === cell).label, filter: selectFilter({ options: () => selectOptions }) }]; Lợi ích là // es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';9 sẽ hiển thị các tùy chọn đã chọn theo thứ tự của mảng Bộ lọc đa lựa chọnMột ví dụ nhanh import filterFactory, { multiSelectFilter } from 'react-bootstrap-table2-filter'; // omit... const selectOptions = { 0: 'good', 1: 'Bad', 2: 'unknown' }; const columns = [ ..., { dataField: 'quality', text: 'Product Quailty', formatter: cell => selectOptions[cell], filter: multiSelectFilter({ options: selectOptions }) }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } /> Sau đây là một ví dụ cho bộ lọc chọn tùy chỉnh import filterFactory, { multiSelectFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const qualityFilter = multiSelectFilter({ options: selectOptions, placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: '2', // default filtering value comparator: Comparator.LIKE, // default is Comparator.EQ style: { .. }, // your custom styles on input withoutEmptyOption: true // hide the default select option id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit... Bộ lọc số// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';0 Bộ lọc số giống như các bộ lọc khác, bạn có thể tùy chỉnh bộ lọc số thông qua chức năng nhà máy import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />4 // es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';1 Bộ lọc ngày// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';2
Bộ lọc ngày cũng giống như các bộ lọc khác, bạn có thể tùy chỉnh bộ lọc ngày thông qua chức năng nhà máy import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />6 // es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';3 Bộ lọc tùy chỉnh// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';4 Trong trường hợp bộ lọc tùy chỉnh, bạn phải hoàn thành hai bước sau
cột. bộ lọcRendererHàm này sẽ truyền hai đối số cho bạn
Cuối cùng, hãy nhớ trả lại thành phần bộ lọc tùy chỉnh của bạn bộ lọc tùy chỉnhChức năng của import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />7 giống như chức năng của import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...3, import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...4, v.v., đó là vì lý do tùy chỉnh. Tuy nhiên, trong trường hợp bộ lọc tùy chỉnh, chỉ có một đạo cụ là hợp lệ. import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...5 // es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';5 import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...5 là một cách để yêu cầu import filterFactory, { textFilter } from 'react-bootstrap-table2-filter'; // omit... const columns = [ ..., { dataField: 'price', text: 'Product Price', filter: textFilter() }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />1 lọc dữ liệu của bạn dưới dạng số, chọn, ngày hoặc văn bản bình thường FILTER_TYPESCác thuộc tính sau có giá trị trong import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...8
Chức vụBộ lọc mặc định được hiển thị bên trong tiêu đề cột của bảng, nhưng bạn có thể chọn hiển thị chúng dưới dạng một hàng trước import filterFactory, { textFilter, Comparator } from 'react-bootstrap-table2-filter'; // omit... const priceFilter = textFilter({ placeholder: 'My Custom PlaceHolder', // custom the input placeholder className: 'my-custom-text-filter', // custom classname on input defaultValue: 'test', // default filtering value comparator: Comparator.EQ, // default is Comparator.LIKE caseSensitive: true, // default is false, and true will only work when comparator is LIKE style: { .. }, // your custom styles on input delay: 1000, // how long will trigger filtering after user typing, default is 500 ms id: 'id', // assign a unique value for htmlFor attribute, it's useful when you have same dataField across multiple table in one page }); // omit...9 Kết xuất ở phần trên cùng của thân bảng// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';6 Kết xuất ở dưới cùng của thân bảng// es5 require('react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css'); // es6 import 'react-bootstrap-table2-filter/dist/react-bootstrap-table2-filter.min.css';7 Cấu hìnhimport filterFactory, { selectFilter } from 'react-bootstrap-table2-filter'; // omit... const selectOptions = { 0: 'good', 1: 'Bad', 2: 'unknown' }; const columns = [ ..., { dataField: 'quality', text: 'Product Quailty', formatter: cell => selectOptions[cell], filter: selectFilter({ options: selectOptions }) }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />0 là chức năng xuất xưởng để khởi tạo một số cấu hình nội bộ. Dưới đây là các tùy chọn có sẵn cho import filterFactory, { selectFilter } from 'react-bootstrap-table2-filter'; // omit... const selectOptions = { 0: 'good', 1: 'Bad', 2: 'unknown' }; const columns = [ ..., { dataField: 'quality', text: 'Product Quailty', formatter: cell => selectOptions[cell], filter: selectFilter({ options: selectOptions }) }]; <BootstrapTable keyField='id' data={ products } columns={ columns } filter={ filterFactory() } />0 bộ lọc sauHàm hook này sẽ được gọi với hai đối số (kết quả bộ lọc mới và đối tượng bộ lọc) khi quá trình lọc hoàn tất |