-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve multi cell selection for horizontal layout and release versio…
…n patch
- Loading branch information
1 parent
12c814e
commit 72ba3ce
Showing
8 changed files
with
383 additions
and
34 deletions.
There are no files selected for viewing
193 changes: 193 additions & 0 deletions
193
examples/src/pages/tests/table/props/filtering/filter-value/custom-filter-operator2.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
import * as React from 'react'; | ||
|
||
import { | ||
InfiniteTable, | ||
InfiniteTablePropColumns, | ||
useInfiniteColumnFilterEditor, | ||
} from '@infinite-table/infinite-react'; | ||
import { DataSource } from '@infinite-table/infinite-react'; | ||
|
||
type Developer = { | ||
id: number; | ||
firstName: string; | ||
lastName: string; | ||
|
||
currency: string; | ||
preferredLanguage: string; | ||
stack: string; | ||
canDesign: 'yes' | 'no'; | ||
|
||
salary: number; | ||
}; | ||
|
||
const data: Developer[] = [ | ||
{ | ||
id: 1, | ||
firstName: 'John', | ||
lastName: 'Bob', | ||
salary: 2000, | ||
canDesign: 'yes', | ||
currency: 'USD', | ||
preferredLanguage: 'JavaScript', | ||
stack: 'frontend', | ||
}, | ||
{ | ||
id: 2, | ||
firstName: 'Marry', | ||
lastName: 'Bob', | ||
salary: 3500, | ||
canDesign: 'yes', | ||
currency: 'USD', | ||
preferredLanguage: 'JavaScript', | ||
stack: 'frontend', | ||
}, | ||
{ | ||
id: 3, | ||
firstName: 'Bill', | ||
lastName: 'Bobson', | ||
salary: 3000, | ||
canDesign: 'no', | ||
currency: 'CAD', | ||
preferredLanguage: 'TypeScript', | ||
stack: 'frontend', | ||
}, | ||
{ | ||
id: 4, | ||
firstName: 'Mark', | ||
lastName: 'Twain', | ||
salary: 1000, | ||
canDesign: 'yes', | ||
currency: 'CAD', | ||
preferredLanguage: 'Rust', | ||
stack: 'backend', | ||
}, | ||
{ | ||
id: 5, | ||
firstName: 'Matthew', | ||
lastName: 'Hilson', | ||
salary: 12900, | ||
canDesign: 'yes', | ||
currency: 'CAD', | ||
preferredLanguage: 'Go', | ||
stack: 'backend', | ||
}, | ||
]; | ||
import { defaultFilterTypes } from '@infinite-table/infinite-react'; | ||
|
||
console.log(defaultFilterTypes); | ||
|
||
const includesOperator = defaultFilterTypes.string.operators.find( | ||
(op) => op.name === 'includes', | ||
); | ||
|
||
includesOperator!.fn = ({ currentValue, filterValue }) => { | ||
if (filterValue && filterValue.startsWith('-')) { | ||
return !currentValue | ||
.toLowerCase() | ||
.includes(filterValue.slice(1).toLowerCase()); | ||
} | ||
return ( | ||
typeof currentValue === 'string' && | ||
typeof filterValue == 'string' && | ||
currentValue.toLowerCase().includes(filterValue.toLowerCase()) | ||
); | ||
}; | ||
|
||
const columns: InfiniteTablePropColumns<Developer> = { | ||
id: { | ||
field: 'id', | ||
}, | ||
firstName: { | ||
field: 'firstName', | ||
}, | ||
salary: { | ||
defaultFilterable: true, | ||
field: 'salary', | ||
type: 'number', | ||
filterType: 'salary', | ||
}, | ||
stack: { field: 'stack' }, | ||
currency: { field: 'currency', defaultFilterable: false }, | ||
}; | ||
|
||
export default () => { | ||
return ( | ||
<> | ||
<React.StrictMode> | ||
<DataSource<Developer> | ||
data={data} | ||
primaryKey="id" | ||
defaultFilterValue={[]} | ||
filterDelay={0} | ||
filterTypes={{ | ||
salary: { | ||
defaultOperator: '', | ||
emptyValues: [], | ||
components: { | ||
FilterEditor: () => { | ||
const { operator, filtered } = | ||
useInfiniteColumnFilterEditor(); | ||
return ( | ||
<div data-operator="default-filter-type-editor"> | ||
{filtered ? ( | ||
<>Operator {operator?.name}</> | ||
) : ( | ||
'Not applied' | ||
)} | ||
</div> | ||
); | ||
}, | ||
}, | ||
operators: [ | ||
{ | ||
name: 'low', | ||
fn: ({ currentValue, filterValue, emptyValues }) => { | ||
if ( | ||
emptyValues.includes(currentValue) || | ||
emptyValues.includes(filterValue) | ||
) { | ||
return true; | ||
} | ||
return currentValue <= 1000; | ||
}, | ||
}, | ||
{ | ||
name: 'medium', | ||
fn: ({ currentValue }) => { | ||
return currentValue > 1000 && currentValue < 10000; | ||
}, | ||
|
||
components: { | ||
FilterEditor: () => ( | ||
<div data-operator="medium">Medium</div> | ||
), | ||
}, | ||
}, | ||
{ | ||
name: 'high', | ||
fn: ({ currentValue }) => { | ||
return currentValue >= 10000; | ||
}, | ||
components: { | ||
FilterEditor: () => <div data-operator="high">High</div>, | ||
}, | ||
}, | ||
], | ||
}, | ||
}} | ||
> | ||
<InfiniteTable<Developer> | ||
domProps={{ | ||
style: { | ||
height: '100%', | ||
}, | ||
}} | ||
columnDefaultWidth={150} | ||
columnMinWidth={50} | ||
columns={columns} | ||
/> | ||
</DataSource> | ||
</React.StrictMode> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.