diff --git a/src/components/Table/index.ts b/src/components/Table/index.ts index b252ae4..bf62c31 100644 --- a/src/components/Table/index.ts +++ b/src/components/Table/index.ts @@ -38,14 +38,14 @@ interface columnPropsOther { initialValue?: string|number } -export const makeColumn = (title:string|any, key:string, other?:columnPropsOther) => ({ +export const makeColumn = (title:string, key:string, other?:columnPropsOther) => ({ title: title, key: key, dataIndex: key, ...other, }) -export const makeColumnsPlanFact = (title:string|any, key:string|string[], columsOther?:any|any[], gruopOther?:any) => +export const makeColumnsPlanFact = (title:string, key:string|string[], columsOther?:any|any[], gruopOther?:any) => { let keyPlanLocal = key let keyFactLocal = key @@ -77,47 +77,49 @@ export const makeColumnsPlanFact = (title:string|any, key:string|string[], colum export const makeFilterTextMatch = (key: string | number) => (filterValue: string | number, dataItem: any) => dataItem[key] === filterValue -export const makeNumericSorter = (key: any) => (a: any, b: any) => a[key] - b[key] +export const makeNumericSorter = (key: string) => (a: any, b: any) => a[key] - b[key] -export const makeStringSorter = (key: any) => (a: any, b: any) => +export const makeStringSorter = (key: string) => (a: any, b: any) => { -for (let i = 0; i < a.length; i++) { - if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i))) - return 1 + for (let i = 0; i < a.length; i++) { + if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i))) + return 1 - if (a.charCodeAt(i) > b.charCodeAt(i)) - return -1 -} -return 0 + if (a.charCodeAt(i) > b.charCodeAt(i)) + return -1 + } + return 0 } -export const makeGroupColumn = (title: any, children: any) => ({ +export const makeGroupColumn = (title: string, children: object[]) => ({ title: title, children: children, }) -export const makeTextColumn = (title: any, dataIndex: any, filters: any, sorter: any, render: any, other: any) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filters ? makeFilterTextMatch(dataIndex) : null, - sorter: sorter ? makeStringSorter(dataIndex) : null, - render: render, - ...other +export const makeTextColumn = (title: string, dataIndex: string, + filters: object[], sorter?: (key: string) => any, render?: any, other?: any) => ({ + title: title, + dataIndex: dataIndex, + key: dataIndex, + filters: filters, + onFilter: filters ? makeFilterTextMatch(dataIndex) : null, + sorter: sorter ? makeStringSorter(dataIndex) : null, + render: render, + ...other }) -export const makeNumericColumn = (title: any, dataIndex: any, filters: any, filterDelegate: (key: string | number) => any, width: string) => ({ - title: title, - dataIndex: dataIndex, - key: dataIndex, - filters: filters, - onFilter: filterDelegate ? filterDelegate(dataIndex) : null, - sorter: makeNumericSorter(dataIndex), - width: width +export const makeNumericColumn = (title: string, dataIndex: string, + filters: object[], filterDelegate: (key: string | number) => any, width: string) => ({ + title: title, + dataIndex: dataIndex, + key: dataIndex, + filters: filters, + onFilter: filterDelegate ? filterDelegate(dataIndex) : null, + sorter: makeNumericSorter(dataIndex), + width: width }) -export const makeNumericColumnPlanFact = (title: any, dataIndex: any, filters: any, filterDelegate: (key: string | number) => any, width: string) => +export const makeNumericColumnPlanFact = (title: string, dataIndex: string, filters: object[], filterDelegate: (key: string | number) => any, width: string) => makeGroupColumn( title, [ makeNumericColumn('п', dataIndex + 'Plan', filters, filterDelegate, width), makeNumericColumn('ф', dataIndex + 'Fact', filters, filterDelegate, width),