diff --git a/src/components/Table/Columns/numeric.tsx b/src/components/Table/Columns/numeric.tsx index 1b2ed3b..a205283 100755 --- a/src/components/Table/Columns/numeric.tsx +++ b/src/components/Table/Columns/numeric.tsx @@ -1,7 +1,7 @@ import { InputNumber } from 'antd' import { ReactNode } from 'react' -import { makeNumericSorter } from '../sorters' +import { makeNumericSorter, makeObjNumericSorter } from '../sorters' import { columnPropsOther, makeGroupColumn, RenderMethod } from '.' export const RegExpIsFloat = /^[-+]?\d+\.?\d*$/ @@ -21,6 +21,25 @@ export const makeNumericRender = (fixed?: number): RenderMeth ) } +type ObjRenderType = { + max: number + avg: number + min: number + isMax: boolean + isMin: boolean +} + +export const makeObjRender = (key: keyof ObjRenderType, boolKey?: keyof ObjRenderType): RenderMethod => (value: ObjRenderType) => { + const val = key ? value[key]: '-' + const isSelected = boolKey ? value[boolKey] : false + + return ( +
+ {val} +
+ ) +} + export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): columnPropsOther => ({ editable: true, initialValue: 0, @@ -34,6 +53,19 @@ export const makeNumericColumnOptions = (fixed?: number, sorterKey?: string): co render: makeNumericRender(fixed), }) +export const makeObjColumnOptions = (key: keyof ObjRenderType, sortedObj?: string, boolKey?: keyof ObjRenderType): columnPropsOther => ({ + editable: true, + initialValue: 0, + width: 100, + sorter: sortedObj && key ? makeObjNumericSorter(sortedObj, key) : undefined, + formItemRules: [{ + required: true, + message: 'Введите число', + pattern: RegExpIsFloat, + }], + render: makeObjRender(key, boolKey), +}) + export const makeNumericColumn = ( title: ReactNode, dataIndex: string, @@ -103,9 +135,9 @@ export const makeNumericAvgRange = ( renderDelegate: (_: any, row: object) => any, width: string ) => makeGroupColumn(title, [ - makeNumericColumn('мин', dataIndex + 'Min', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Min')), - makeNumericColumn('сред', dataIndex + 'Avg', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Avg')), - makeNumericColumn('макс', dataIndex + 'Max', filters, filterDelegate, renderDelegate, width, makeNumericColumnOptions(fixed, dataIndex + 'Max')) + makeNumericColumn('мин', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('min', dataIndex, 'isMin')), + makeNumericColumn('сред', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('avg', dataIndex)), + makeNumericColumn('макс', dataIndex, filters, filterDelegate, renderDelegate, width, makeObjColumnOptions('max', dataIndex, 'isMax')) ]) export default makeNumericColumn diff --git a/src/components/Table/sorters.ts b/src/components/Table/sorters.ts index 11fb7e2..f0a1ac9 100755 --- a/src/components/Table/sorters.ts +++ b/src/components/Table/sorters.ts @@ -7,6 +7,9 @@ import { DataType } from './Columns' export const makeNumericSorter = (key: keyof DataType) => (a: DataType, b: DataType) => Number(a[key]) - Number(b[key]) +export const makeObjNumericSorter = (obj: keyof DataType, key: keyof DataType) => + (a: DataType>, b: DataType>) => Number(a[obj][key]) - Number(b[obj][key]) + export const makeStringSorter = (key: keyof DataType) => (a?: DataType | null, b?: DataType | null) => { if (!a && !b) return 0 if (!a) return 1 diff --git a/src/pages/WellOperations/WellDrillParams.jsx b/src/pages/WellOperations/WellDrillParams.jsx index 6391023..aab2d2d 100755 --- a/src/pages/WellOperations/WellDrillParams.jsx +++ b/src/pages/WellOperations/WellDrillParams.jsx @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, memo, useMemo } from 'react' import { useWell } from '@asb/context' import { - EditableTable, + Table, makeSelectColumn, makeNumericAvgRange, makeNumericSorter, @@ -81,15 +81,12 @@ export const WellDrillParams = memo(() => { return ( - diff --git a/src/styles/index.css b/src/styles/index.css index b095532..bde3eb8 100755 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -141,4 +141,16 @@ code { .download-link { height: 32px; padding: 4px 15px; +} + +.ant-table-cell:has(.color-pale-green) { + background-color: #98fb98; +} + +.ant-table-tbody > tr > td.ant-table-cell-row-hover:has( > div.color-pale-green) { + background: #98fb98; +} + +.color-pale-green { + background-color: #98fb98; } \ No newline at end of file