Added types to index.ts in 'Table'

This commit is contained in:
KharchenkoVV 2021-08-30 12:39:46 +05:00
parent f6e896d8f3
commit a0e6783f97

View File

@ -38,14 +38,14 @@ interface columnPropsOther {
initialValue?: string|number initialValue?: string|number
} }
export const makeColumn = (title:string|any, key:string, other?:columnPropsOther) => ({ export const makeColumn = (title:string, key:string, other?:columnPropsOther) => ({
title: title, title: title,
key: key, key: key,
dataIndex: key, dataIndex: key,
...other, ...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 keyPlanLocal = key
let keyFactLocal = 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) => export const makeFilterTextMatch = (key: string | number) => (filterValue: string | number, dataItem: any) =>
dataItem[key] === filterValue 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++) { for (let i = 0; i < a.length; i++) {
if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i))) if (isNaN(b.charCodeAt(i)) || (a.charCodeAt(i) > b.charCodeAt(i)))
return 1 return 1
if (a.charCodeAt(i) > b.charCodeAt(i)) if (a.charCodeAt(i) > b.charCodeAt(i))
return -1 return -1
} }
return 0 return 0
} }
export const makeGroupColumn = (title: any, children: any) => ({ export const makeGroupColumn = (title: string, children: object[]) => ({
title: title, title: title,
children: children, children: children,
}) })
export const makeTextColumn = (title: any, dataIndex: any, filters: any, sorter: any, render: any, other: any) => ({ export const makeTextColumn = (title: string, dataIndex: string,
title: title, filters: object[], sorter?: (key: string) => any, render?: any, other?: any) => ({
dataIndex: dataIndex, title: title,
key: dataIndex, dataIndex: dataIndex,
filters: filters, key: dataIndex,
onFilter: filters ? makeFilterTextMatch(dataIndex) : null, filters: filters,
sorter: sorter ? makeStringSorter(dataIndex) : null, onFilter: filters ? makeFilterTextMatch(dataIndex) : null,
render: render, sorter: sorter ? makeStringSorter(dataIndex) : null,
...other render: render,
...other
}) })
export const makeNumericColumn = (title: any, dataIndex: any, filters: any, filterDelegate: (key: string | number) => any, width: string) => ({ export const makeNumericColumn = (title: string, dataIndex: string,
title: title, filters: object[], filterDelegate: (key: string | number) => any, width: string) => ({
dataIndex: dataIndex, title: title,
key: dataIndex, dataIndex: dataIndex,
filters: filters, key: dataIndex,
onFilter: filterDelegate ? filterDelegate(dataIndex) : null, filters: filters,
sorter: makeNumericSorter(dataIndex), onFilter: filterDelegate ? filterDelegate(dataIndex) : null,
width: width 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, [ makeGroupColumn( title, [
makeNumericColumn('п', dataIndex + 'Plan', filters, filterDelegate, width), makeNumericColumn('п', dataIndex + 'Plan', filters, filterDelegate, width),
makeNumericColumn('ф', dataIndex + 'Fact', filters, filterDelegate, width), makeNumericColumn('ф', dataIndex + 'Fact', filters, filterDelegate, width),