diff --git a/src/Examples/gridconsumer/gridconfig.tsx b/src/Examples/gridconsumer/gridconfig.tsx index 98ef5e1..1def2ec 100644 --- a/src/Examples/gridconsumer/gridconfig.tsx +++ b/src/Examples/gridconsumer/gridconfig.tsx @@ -7,201 +7,215 @@ import { IColumnConfig } from "../../libs/types/columnconfigtype"; import { EditControlType } from "../../libs/types/editcontroltype"; import { CellHover } from "./hoverComponent"; -export const GridColumnConfig : IColumnConfig[] = -[ - { - key: 'id', - name: 'ID', - text: 'ID', - editable: false, - dataType: 'number', - minWidth: 100, - maxWidth: 100, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - applyColumnFilter: true, - disableSort: true - }, - { - key: 'customerhovercol', - name: 'Custom Hover Column', - text: 'Custom Hover Column', - editable: false, - dataType: 'string', - minWidth: 150, - maxWidth: 150, - isResizable: true, - includeColumnInExport: false, - includeColumnInSearch: false, - applyColumnFilter: false, - disableSort: true, - hoverComponentOptions: { enable:true, hoverChildComponent: } - }, - { - key: 'name', - name: 'Name', - text: 'Name', - editable: true, - dataType: 'string', - minWidth: 100, - maxWidth: 100, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - applyColumnFilter: true - }, - { - key: 'password', - name: 'Password', - text: 'Password', - editable: true, - dataType: 'string', - minWidth: 100, - maxWidth: 100, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - applyColumnFilter: true, - inputType: EditControlType.Password - }, - { - key: 'age', - name: 'Age', - text: 'Age', - editable: true, - dataType: 'number', - minWidth: 100, - maxWidth: 100, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - applyColumnFilter: true - }, - { - key: 'designation', - name: 'Designation', - text: 'Designation', - editable: true, - dataType: 'string', - minWidth: 100, - maxWidth: 100, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - inputType: EditControlType.MultilineTextField, - applyColumnFilter: true - }, - { - key: 'salary', - name: 'Salary', - text: 'Salary', - editable: true, - dataType: 'number', - minWidth: 100, - maxWidth: 100, - isResizable: true, - includeColumnInExport: false, - includeColumnInSearch: true, - maxLength:5, - applyColumnFilter: true, - cellStyleRule: { - enable: true, - rule: { - operator : NumberAndDateOperators.LESSTHAN, - value: 50000 - }, - whenTrue: { textColor: '#EF5350', fontWeight: 'bold' }, - whenFalse: { textColor: '#9CCC65' } +export const GridColumnConfig: IColumnConfig[] = + [ + { + key: 'id', + name: 'ID', + text: 'ID', + editable: false, + dataType: 'number', + minWidth: 100, + maxWidth: 100, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + applyColumnFilter: true, + disableSort: true + }, + { + key: 'customerhovercol', + name: 'Custom Hover Column', + text: 'Custom Hover Column', + editable: false, + dataType: 'string', + minWidth: 150, + maxWidth: 150, + isResizable: true, + includeColumnInExport: false, + includeColumnInSearch: false, + applyColumnFilter: false, + disableSort: true, + hoverComponentOptions: { enable: true, hoverChildComponent: } + }, + { + key: 'name', + name: 'Name', + text: 'Name', + editable: true, + dataType: 'string', + minWidth: 100, + maxWidth: 100, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + applyColumnFilter: true + }, + { + key: 'password', + name: 'Password', + text: 'Password', + editable: true, + dataType: 'string', + minWidth: 100, + maxWidth: 100, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + applyColumnFilter: true, + inputType: EditControlType.Password + }, + { + key: 'age', + name: 'Age', + text: 'Age', + editable: true, + dataType: 'number', + minWidth: 100, + maxWidth: 100, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + applyColumnFilter: true + }, + { + key: 'designation', + name: 'Designation', + text: 'Designation', + editable: true, + dataType: 'string', + minWidth: 100, + maxWidth: 100, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + inputType: EditControlType.MultilineTextField, + applyColumnFilter: true + }, + { + key: 'salary', + name: 'Salary', + text: 'Salary', + editable: true, + dataType: 'number', + minWidth: 100, + maxWidth: 100, + isResizable: true, + includeColumnInExport: false, + includeColumnInSearch: true, + maxLength: 5, + applyColumnFilter: true, + cellStyleRule: { + enable: true, + rule: { + operator: NumberAndDateOperators.LESSTHAN, + value: 50000 + }, + whenTrue: { textColor: '#EF5350', fontWeight: 'bold' }, + whenFalse: { textColor: '#9CCC65' } + } + }, + { + key: 'dateofjoining', + name: 'Date of Joining', + text: 'Date of Joining', + editable: true, + dataType: 'date', + minWidth: 200, + maxWidth: 200, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + inputType: EditControlType.Date + }, + { + key: 'lasteupdatetime', + name: 'Update Date & Time', + text: 'Update Date & Time', + editable: true, + dataType: 'date', + minWidth: 150, + maxWidth: 150, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + inputType: EditControlType.DateTime + }, + { + key: 'payrolltype', + name: 'Payroll Type', + text: 'Payroll Type', + editable: true, + dataType: 'string', + minWidth: 150, + maxWidth: 150, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + inputType: EditControlType.DropDown, + dropdownValues: [ + { key: 'weekly', text: 'Weekly' }, + { key: 'biweekly', text: 'Bi-Weekly' }, + { key: 'monthly', text: 'Monthly' } + ] + }, + { + key: 'employmenttype', + name: 'Employment Type', + text: 'Employment Type', + editable: true, + dataType: 'string', + minWidth: 200, + maxWidth: 200, + isResizable: true, + includeColumnInExport: true, + includeColumnInSearch: true, + inputType: EditControlType.Picker, + pickerOptions: { + pickerTags: ['Employment Type1', 'Employment Type2', 'Employment Type3', 'Employment Type4', 'Employment Type5', 'Employment Type6', 'Employment Type7', 'Employment Type8', 'Employment Type9', 'Employment Type10', 'Employment Type11', 'Employment Type12'], + minCharLimitForSuggestions: 2, + tagsLimit: 1, + pickerDescriptionOptions: { + enabled: true, + values: [ + { key: 'Employment Type1', description: 'Employment Type1 Description' }, + { key: 'Employment Type2', description: 'Employment Type2 Description' }, + { key: 'Employment Type3', description: 'Employment Type3 Description' }, + { key: 'Employment Type4', description: 'Employment Type4 Description' }, + { key: 'Employment Type5', description: 'Employment Type5 Description' }, + { key: 'Employment Type6', description: 'Employment Type6 Description' }, + { key: 'Employment Type7', description: 'Employment Type7 Description' }, + { key: 'Employment Type8', description: 'Employment Type8 Description' }, + { key: 'Employment Type9', description: 'Employment Type9 Description' }, + { key: 'Employment Type10', description: 'Employment Type10 Description' }, + { key: 'Employment Type11', description: 'Employment Type11 Description' }, + { key: 'Employment Type12', description: 'Employment Type12 Description' }, + ] + }, + suggestionsRule: StringOperators.STARTSWITH + } + }, + { + key: 'employeelink', + name: 'Employee Profile Link', + text: 'Employee Profile Link', + editable: false, + dataType: 'string', + minWidth: 150, + maxWidth: 150, + isResizable: true, + includeColumnInExport: false, + includeColumnInSearch: false, + inputType: EditControlType.Link, + linkOptions: { + onClick: () => { // onClick takes higher precedence over href. If both are enabled, the grid will trigger onClick + alert('clicked') + }, + //href: 'https://www.bing.com/', + disabled: false + } } - }, - { - key: 'dateofjoining', - name: 'Date of Joining', - text: 'Date of Joining', - editable: true, - dataType: 'date', - minWidth: 150, - maxWidth: 150, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - inputType: EditControlType.Date - }, - { - key: 'payrolltype', - name: 'Payroll Type', - text: 'Payroll Type', - editable: true, - dataType: 'string', - minWidth: 150, - maxWidth: 150, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - inputType: EditControlType.DropDown, - dropdownValues: [ - { key: 'weekly', text: 'Weekly' }, - { key: 'biweekly', text: 'Bi-Weekly' }, - { key: 'monthly', text: 'Monthly' } - ] - }, - { - key: 'employmenttype', - name: 'Employment Type', - text: 'Employment Type', - editable: true, - dataType: 'string', - minWidth: 200, - maxWidth: 200, - isResizable: true, - includeColumnInExport: true, - includeColumnInSearch: true, - inputType: EditControlType.Picker, - pickerOptions: { - pickerTags: ['Employment Type1', 'Employment Type2', 'Employment Type3', 'Employment Type4', 'Employment Type5', 'Employment Type6', 'Employment Type7', 'Employment Type8', 'Employment Type9', 'Employment Type10', 'Employment Type11', 'Employment Type12'], - minCharLimitForSuggestions: 2, - tagsLimit: 1, - pickerDescriptionOptions: { - enabled: true, - values: [ - { key: 'Employment Type1', description: 'Employment Type1 Description'}, - { key: 'Employment Type2', description: 'Employment Type2 Description'}, - { key: 'Employment Type3', description: 'Employment Type3 Description'}, - { key: 'Employment Type4', description: 'Employment Type4 Description'}, - { key: 'Employment Type5', description: 'Employment Type5 Description'}, - { key: 'Employment Type6', description: 'Employment Type6 Description'}, - { key: 'Employment Type7', description: 'Employment Type7 Description'}, - { key: 'Employment Type8', description: 'Employment Type8 Description'}, - { key: 'Employment Type9', description: 'Employment Type9 Description'}, - { key: 'Employment Type10', description: 'Employment Type10 Description'}, - { key: 'Employment Type11', description: 'Employment Type11 Description'}, - { key: 'Employment Type12', description: 'Employment Type12 Description'}, - ] }, - suggestionsRule: StringOperators.STARTSWITH - } - }, - { - key: 'employeelink', - name: 'Employee Profile Link', - text: 'Employee Profile Link', - editable: false, - dataType: 'string', - minWidth: 150, - maxWidth: 150, - isResizable: true, - includeColumnInExport: false, - includeColumnInSearch: false, - inputType: EditControlType.Link, - linkOptions: { - onClick: () => { // onClick takes higher precedence over href. If both are enabled, the grid will trigger onClick - alert('clicked') - }, - //href: 'https://www.bing.com/', - disabled: false - } - } -]; + ]; export interface GridItemsType { id: number; @@ -212,6 +226,7 @@ export interface GridItemsType { designation: string; salary: number; dateofjoining: string; + lasteupdatetime: string; payrolltype: string; employmenttype: string; employeelink: string; diff --git a/src/Examples/gridconsumer/gridconsumer.tsx b/src/Examples/gridconsumer/gridconsumer.tsx index f784aac..0f26d09 100644 --- a/src/Examples/gridconsumer/gridconsumer.tsx +++ b/src/Examples/gridconsumer/gridconsumer.tsx @@ -41,7 +41,7 @@ const Consumer = () => { const [items, setItems] = useState([]); const [teachingBubbleVisible, { toggle: toggleTeachingBubbleVisible }] = useBoolean(true); - const [teachingBubblePropsConfig, setTeachingBubblePropsConfig] = useState({ id: 0, config: {...teachingBubbleConfig[0], footerContent: `1 of ${teachingBubbleConfig.length}`}}); + const [teachingBubblePropsConfig, setTeachingBubblePropsConfig] = useState({ id: 0, config: { ...teachingBubbleConfig[0], footerContent: `1 of ${teachingBubbleConfig.length}` } }); const [gridConfigOptions, setGridConfigOptions] = useState({ enableCellEdit: true, enableRowEdit: true, @@ -68,18 +68,18 @@ const Consumer = () => { const classNames = mergeStyleSets({ controlWrapper: { - display: 'flex', - flexWrap: 'wrap', + display: 'flex', + flexWrap: 'wrap', }, detailsDiv: { border: '3px solid black', margin: '5px' }, - detailsValues:{ - color:'#0078d4' + detailsValues: { + color: '#0078d4' }, - checkbox:{ - width:'250px' + checkbox: { + width: '250px' } }); @@ -93,8 +93,8 @@ const Consumer = () => { margin: "0px 0px 0px 30px" }); - const onTeachingBubbleNavigation = (direction : string) => { - switch(direction) { + const onTeachingBubbleNavigation = (direction: string) => { + switch (direction) { case 'previous': var TeachingProps = teachingBubbleConfig[teachingBubblePropsConfig.id - 1]; var currentId = teachingBubblePropsConfig.id - 1; @@ -113,9 +113,9 @@ const Consumer = () => { setTeachingBubblePropsConfig({ id: 0, config: TeachingProps }); toggleTeachingBubbleVisible(); break; - } + } } - + const nextBubbleProps: IButtonProps = { children: 'Next', onClick: () => onTeachingBubbleNavigation('next'), @@ -130,34 +130,35 @@ const Consumer = () => { onClick: () => onTeachingBubbleNavigation('close'), }; - const GetRandomDate = (start : Date, end : Date) : Date => { - var diff = end.getTime() - start.getTime(); + const GetRandomDate = (start: Date, end: Date): Date => { + var diff = end.getTime() - start.getTime(); var new_diff = diff * Math.random(); var date = new Date(start.getTime() + new_diff); return date; } - const GetRandomInt = (min : number, max : number) : number => { + const GetRandomInt = (min: number, max: number): number => { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min + 1)) + min; }; - const SetDummyData = () : void => { - var dummyData : GridItemsType[] = [] - for(var i = 1; i <= 100; i++){ - var randomInt = GetRandomInt(1,3); + const SetDummyData = (): void => { + var dummyData: GridItemsType[] = [] + for (var i = 1; i <= 100; i++) { + var randomInt = GetRandomInt(1, 3); dummyData.push({ id: i, customerhovercol: 'Hover Me', - name: 'Name'+ GetRandomInt(1, 10), + name: 'Name' + GetRandomInt(1, 10), password: "somepassword", - age: GetRandomInt(20,40), + age: GetRandomInt(20, 40), designation: 'Designation' + GetRandomInt(1, 15), salary: GetRandomInt(35000, 75000), dateofjoining: '2010-10-10T14:57:10', + lasteupdatetime: '2010-10-10T14:57:11', payrolltype: randomInt % 3 == 0 ? 'Weekly' : randomInt % 3 == 1 ? 'Bi-Weekly' : 'Monthly', - employmenttype: 'Employment Type' + GetRandomInt(1,12), + employmenttype: 'Employment Type' + GetRandomInt(1, 12), employeelink: 'Link' }); } @@ -173,7 +174,7 @@ const Consumer = () => { alert('Grid Data Saved'); LogRows(data); setItems([...data.filter(y => y._grid_row_operation_ != Operation.Delete).map(x => { - return {...x, '_grid_row_operation_': Operation.None} + return { ...x, '_grid_row_operation_': Operation.None } })]); }; @@ -182,7 +183,7 @@ const Consumer = () => { LogRows(data); }; - const LogRows = (data: any[]) : void => { + const LogRows = (data: any[]): void => { console.log('Updated Rows'); console.log(data.filter(item => item._grid_row_operation_ == Operation.Update)); console.log('Added Rows'); @@ -193,22 +194,22 @@ const Consumer = () => { console.log(data.filter(item => item._grid_row_operation_ == Operation.None)); } - const onPayrollChanged = (callbackRequestParamObj : ICallBackParams): any[] => { + const onPayrollChanged = (callbackRequestParamObj: ICallBackParams): any[] => { alert('Payroll Changed'); return callbackRequestParamObj.data; } - const onDateChanged = (callbackRequestParamObj : ICallBackParams): any[] => { + const onDateChanged = (callbackRequestParamObj: ICallBackParams): any[] => { alert('Date Changed'); return callbackRequestParamObj.data; } - const onEmploymentTypeChanged = (callbackRequestParamObj : ICallBackParams): any[] => { + const onEmploymentTypeChanged = (callbackRequestParamObj: ICallBackParams): any[] => { alert('Employment Type Changed'); return callbackRequestParamObj.data; } - const onDesignationChanged = (callbackRequestParamObj : ICallBackParams): any[] => { + const onDesignationChanged = (callbackRequestParamObj: ICallBackParams): any[] => { callbackRequestParamObj.rowindex.forEach((index) => { callbackRequestParamObj.data.filter((item) => item._grid_row_id_ == index).map((item) => item.salary = 30000); }); @@ -216,7 +217,7 @@ const Consumer = () => { return callbackRequestParamObj.data; } - const attachGridValueChangeCallbacks = (columnConfig : IColumnConfig[]) : IColumnConfig[] => { + const attachGridValueChangeCallbacks = (columnConfig: IColumnConfig[]): IColumnConfig[] => { //columnConfig.filter((item) => item.key == 'designation').map((item) => item.onChange = onDesignationChanged); //columnConfig.filter((item) => item.key == 'employmenttype').map((item) => item.onChange = onEmploymentTypeChanged); //columnConfig.filter((item) => item.key == 'payrolltype').map((item) => item.onChange = onPayrollChanged); @@ -225,7 +226,7 @@ const Consumer = () => { }; const onCheckboxChange = (ev?: React.FormEvent, checked?: boolean): void => { - setGridConfigOptions({...gridConfigOptions, [(ev!.target as Element).id]: !gridConfigOptions[(ev!.target as Element).id] }) + setGridConfigOptions({ ...gridConfigOptions, [(ev!.target as Element).id]: !gridConfigOptions[(ev!.target as Element).id] }) }; return ( @@ -300,10 +301,10 @@ const Consumer = () => {
- EventEmitter.dispatch(EventType.onSearch, event)}/> + EventEmitter.dispatch(EventType.onSearch, event)} /> - { enableGridReset={gridConfigOptions.enableGridReset} enableColumnFilters={gridConfigOptions.enableColumnFilters} enableColumnFilterRules={gridConfigOptions.enableColumnFilterRules} - enableRowAddWithValues={{enable : gridConfigOptions.enableRowAddWithValues, enableRowsCounterInPanel : true}} - gridCopyOptions={{enableGridCopy: gridConfigOptions.enableGridCopy, enableRowCopy: gridConfigOptions.enableRowCopy}} + enableRowAddWithValues={{ enable: gridConfigOptions.enableRowAddWithValues, enableRowsCounterInPanel: true }} + gridCopyOptions={{ enableGridCopy: gridConfigOptions.enableGridCopy, enableRowCopy: gridConfigOptions.enableRowCopy }} onGridStatusMessageCallback={(str) => { toast.info(str, { - position: toast.POSITION.TOP_CENTER + position: toast.POSITION.TOP_CENTER }) }} onGridUpdate={onGridUpdate} @@ -351,7 +352,7 @@ const Consumer = () => { name: "Custom Command Bar Item1", iconProps: { iconName: "Download" }, onClick: () => { - alert('Clicked'); + alert('Clicked'); }, } ]} @@ -359,19 +360,19 @@ const Consumer = () => { {teachingBubbleVisible && ( 0 ? previousBubbleProps : undefined} - onDismiss={toggleTeachingBubbleVisible} - footerContent={teachingBubblePropsConfig?.config.footerContent} - headline={teachingBubblePropsConfig?.config.headline} - hasCloseButton={true} - isWide={teachingBubblePropsConfig?.config.isWide == null ? true : teachingBubblePropsConfig?.config.isWide} - calloutProps={{ - directionalHint:DirectionalHint.bottomLeftEdge, - }} + target={teachingBubblePropsConfig?.config.target} + primaryButtonProps={teachingBubblePropsConfig?.id < teachingBubbleConfig.length - 1 ? nextBubbleProps : closeButtonProps} + secondaryButtonProps={teachingBubblePropsConfig?.id > 0 ? previousBubbleProps : undefined} + onDismiss={toggleTeachingBubbleVisible} + footerContent={teachingBubblePropsConfig?.config.footerContent} + headline={teachingBubblePropsConfig?.config.headline} + hasCloseButton={true} + isWide={teachingBubblePropsConfig?.config.isWide == null ? true : teachingBubblePropsConfig?.config.isWide} + calloutProps={{ + directionalHint: DirectionalHint.bottomLeftEdge, + }} > - {teachingBubblePropsConfig?.config.innerText} + {teachingBubblePropsConfig?.config.innerText} )} diff --git a/src/Examples/gridconsumer/hoverComponent.tsx b/src/Examples/gridconsumer/hoverComponent.tsx index 59d2a41..2236a62 100644 --- a/src/Examples/gridconsumer/hoverComponent.tsx +++ b/src/Examples/gridconsumer/hoverComponent.tsx @@ -11,17 +11,17 @@ const CellHoverComponent: FC = (props) => { return (
-

Custom Hover Component

-
Row Number: {props.rowNum}
-
Column: {props.column.name}
-
ID: {props.rowData['id']}
-
Name: {props.rowData['name']}
-
Age: {props.rowData['age']}
-
Designation: {props.rowData['designation']}
-
Salary: {props.rowData['salary']}
-
Date Of Joining: {props.rowData['dateofjoining']}
-
Payroll Type: {props.rowData['payrolltype']}
-
Employment Type: {props.rowData['employmenttype']}
+

Custom Hover Component

+
Row Number: {props.rowNum}
+
Column: {props.column?.name}
+
ID: {props.rowData['id']}
+
Name: {props.rowData['name']}
+
Age: {props.rowData['age']}
+
Designation: {props.rowData['designation']}
+
Salary: {props.rowData['salary']}
+
Date Of Joining: {props.rowData['dateofjoining']}
+
Payroll Type: {props.rowData['payrolltype']}
+
Employment Type: {props.rowData['employmenttype']}
); diff --git a/src/libs/editablegrid/addrowpanel.tsx b/src/libs/editablegrid/addrowpanel.tsx index 6a7955c..5fa2bd7 100644 --- a/src/libs/editablegrid/addrowpanel.tsx +++ b/src/libs/editablegrid/addrowpanel.tsx @@ -1,4 +1,4 @@ -import { ConstrainMode, DatePicker, Dropdown, IDropdownOption, IStackStyles, IStackTokens, ITag, ITextFieldStyles, mergeStyleSets, Position, PrimaryButton, SpinButton, Stack, TextField } from "office-ui-fabric-react"; +import { ConstrainMode, DatePicker, Dropdown, IComboBox, IDropdownOption, IStackStyles, IStackTokens, ITag, ITextFieldStyles, mergeStyleSets, Position, PrimaryButton, SpinButton, Stack, TextField } from "office-ui-fabric-react"; import React, { useEffect, useState } from "react"; import { IColumnConfig } from "../types/columnconfigtype"; import { EditControlType } from "../types/editcontroltype"; @@ -6,6 +6,7 @@ import { DayPickerStrings } from "./datepickerconfig"; import { controlClass, horizontalGapStackTokens, stackStyles, textFieldStyles, verticalGapStackTokens } from "./editablegridstyles"; import { GetDefault, IsValidDataType, ParseType } from "./helper"; import PickerControl from "./pickercontrol/picker"; +import { TimePicker } from "@fluentui/react"; interface Props { onChange: any; @@ -16,38 +17,38 @@ interface Props { const AddRowPanel = (props: Props) => { let AddSpinRef: any = React.createRef(); - const updateObj : any = {}; + const updateObj: any = {}; const [columnValuesObj, setColumnValuesObj] = useState(null); useEffect(() => { - let tmpColumnValuesObj : any = {}; + let tmpColumnValuesObj: any = {}; props.columnConfigurationData.forEach((item, index) => { - tmpColumnValuesObj[item.key] = { 'value' : GetDefault(item.dataType), 'isChanged' : false, 'error': null }; + tmpColumnValuesObj[item.key] = { 'value': GetDefault(item.dataType), 'isChanged': false, 'error': null }; }) setColumnValuesObj(tmpColumnValuesObj); }, [props.columnConfigurationData]); - const SetObjValues = (key: string, value: any, isChanged: boolean = true, errorMessage: string | null = null) : void => { - setColumnValuesObj({...columnValuesObj, [key]: { 'value' : value, 'isChanged' : isChanged, 'error': errorMessage }}) + const SetObjValues = (key: string, value: any, isChanged: boolean = true, errorMessage: string | null = null): void => { + setColumnValuesObj({ ...columnValuesObj, [key]: { 'value': value, 'isChanged': isChanged, 'error': errorMessage } }) } - const onDropDownChange = (event: React.FormEvent, selectedDropdownItem: IDropdownOption | undefined, item : any): void => { + const onDropDownChange = (event: React.FormEvent, selectedDropdownItem: IDropdownOption | undefined, item: any): void => { SetObjValues(item.key, selectedDropdownItem?.text); } - const onTextUpdate = (ev: React.FormEvent, text: string, column : IColumnConfig): void => { - if(!IsValidDataType(column.dataType, text)){ + const onTextUpdate = (ev: React.FormEvent, text: string, column: IColumnConfig): void => { + if (!IsValidDataType(column.dataType, text)) { SetObjValues((ev.target as Element).id, text, false, `Data should be of type '${column.dataType}'`); return; } - + SetObjValues((ev.target as Element).id, ParseType(column.dataType, text)); }; const onPanelSubmit = (): void => { var objectKeys = Object.keys(columnValuesObj); objectKeys.forEach((objKey) => { - if(columnValuesObj[objKey]['isChanged']){ + if (columnValuesObj[objKey]['isChanged']) { updateObj[objKey] = columnValuesObj[objKey]['value'] } }); @@ -55,21 +56,50 @@ const AddRowPanel = (props: Props) => { props.onChange(updateObj, props.enableRowsCounterField ? AddSpinRef.current.value : 1); }; - const onCellPickerTagListChanged = (cellPickerTagList: ITag[] | undefined, item : any) : void => { - if(cellPickerTagList && cellPickerTagList[0] && cellPickerTagList[0].name) + const onCellPickerTagListChanged = (cellPickerTagList: ITag[] | undefined, item: any): void => { + if (cellPickerTagList && cellPickerTagList[0] && cellPickerTagList[0].name) SetObjValues(item.key, cellPickerTagList[0].name); else SetObjValues(item.key, ''); } - const onCellDateChange = (date: Date | null | undefined, item : any): void => { - SetObjValues(item.key, date); + const onCellDateChange = (date: Date | null | undefined, item: IColumnConfig): void => { + let currentDate = getColumnValue(item); + + if (currentDate === undefined || currentDate === null) { + currentDate = date; + } else if (date !== null && date !== undefined) { + currentDate.setFullYear(date.getFullYear()); + currentDate.setMonth(date.getMonth()); + currentDate.setDate(date.getDate()); + } + + SetObjValues(item.key, currentDate); + }; + + const onCellTimeChange = (dateTime: Date | null | undefined, item: IColumnConfig): void => { + let currentDate = getColumnValue(item); + + if (currentDate === undefined || currentDate === null) { + currentDate = dateTime; + } else if (dateTime !== null && dateTime !== undefined) { + currentDate.setHours(dateTime.getHours()); + currentDate.setMinutes(dateTime.getMinutes()); + currentDate.setSeconds(dateTime.getSeconds()); + currentDate.setMilliseconds(dateTime.getMilliseconds()); + } + + SetObjValues(item.key, currentDate); }; - const createTextFields = () : any[] => { - let tmpRenderObj : any[] = []; + const getColumnValue = (item: IColumnConfig) => { + return columnValuesObj[item.key].value; + }; + + const createTextFields = (): any[] => { + let tmpRenderObj: any[] = []; props.columnConfigurationData.forEach((item, index) => { - switch(item.inputType){ + switch (item.inputType) { case EditControlType.Date: tmpRenderObj.push( { case EditControlType.Picker: tmpRenderObj.push(
{item.text} - onCellPickerTagListChanged(selectedItem, item)} pickerDescriptionOptions={item.pickerOptions?.pickerDescriptionOptions} - />
); + />
); break; case EditControlType.MultilineTextField: tmpRenderObj.push( { styles={textFieldStyles} onChange={(ev, text) => onTextUpdate(ev, text!, item)} value={columnValuesObj[item.key].value || ''} - />); + />); break; case EditControlType.Password: tmpRenderObj.push( { value={columnValuesObj[item.key].value || ''} type="password" canRevealPassword - />); + />); + break; + case EditControlType.DateTime: + tmpRenderObj.push(
+ + onCellDateChange(date, item)} + /> + { onCellTimeChange(time, item) }} + /> + +
+ ); break; default: tmpRenderObj.push( { styles={textFieldStyles} onChange={(ev, text) => onTextUpdate(ev, text!, item)} value={columnValuesObj[item.key].value || ''} - />); + />); break; } }); - if(props.enableRowsCounterField){ + if (props.enableRowsCounterField) { tmpRenderObj.push( { /> ); } - + return tmpRenderObj; } @@ -168,13 +219,13 @@ const AddRowPanel = (props: Props) => { {columnValuesObj && createTextFields()} - columnValuesObj[k] && columnValuesObj[k].error && columnValuesObj[k].error.length > 0) || false} - /> + columnValuesObj[k] && columnValuesObj[k].error && columnValuesObj[k].error.length > 0) || false} + /> ); diff --git a/src/libs/editablegrid/columnupdatedialog.tsx b/src/libs/editablegrid/columnupdatedialog.tsx index f5c76c5..b40d126 100644 --- a/src/libs/editablegrid/columnupdatedialog.tsx +++ b/src/libs/editablegrid/columnupdatedialog.tsx @@ -8,6 +8,7 @@ import { EditControlType } from "../types/editcontroltype"; import { DayPickerStrings } from "./datepickerconfig"; import { GetDefault, IsValidDataType, ParseType } from "./helper"; import PickerControl from "./pickercontrol/picker"; +import { TimePicker } from "@fluentui/react"; interface Props { columnConfigurationData: IColumnConfig[]; @@ -15,9 +16,9 @@ interface Props { onDialogSave?: any; } -const ColumnUpdateDialog = (props : Props) => { +const ColumnUpdateDialog = (props: Props) => { const controlClass = mergeStyleSets({ - inputClass:{ + inputClass: { display: 'block', width: '100%' }, @@ -27,7 +28,7 @@ const ColumnUpdateDialog = (props : Props) => { }); const textFieldStyles: Partial = { fieldGroup: {} }; - + const [gridColumn, setGridColumn] = useState(''); const [inputValue, setInputValue] = useState(null); @@ -37,29 +38,29 @@ const ColumnUpdateDialog = (props : Props) => { }; useEffect(() => { - let tmpColumnValuesObj : any = {}; + let tmpColumnValuesObj: any = {}; props.columnConfigurationData.filter(x => x.editable == true).forEach((item, index) => { - tmpColumnValuesObj[item.key] = { 'value' : GetDefault(item.dataType), 'isChanged' : false, 'error': null }; + tmpColumnValuesObj[item.key] = { 'value': GetDefault(item.dataType), 'isChanged': false, 'error': null }; }) setInputValue(tmpColumnValuesObj); }, [props.columnConfigurationData]); - const SetObjValues = (key: string, value: any, isChanged: boolean = true, errorMessage: string | null = null) : void => { - var inputValueTmp : any = { ...inputValue }; + const SetObjValues = (key: string, value: any, isChanged: boolean = true, errorMessage: string | null = null): void => { + var inputValueTmp: any = { ...inputValue }; var objectKeys = Object.keys(inputValueTmp); objectKeys.forEach((objKey) => { inputValueTmp[objKey]['isChanged'] = false; }); - inputValueTmp[key] = { 'value' : value, 'isChanged' : isChanged, 'error': errorMessage }; + inputValueTmp[key] = { 'value': value, 'isChanged': isChanged, 'error': errorMessage }; setInputValue(inputValueTmp); } - const onTextUpdate = (ev: React.FormEvent, text: string, column : IColumnConfig): void => { - if(!IsValidDataType(column?.dataType, text)){ + const onTextUpdate = (ev: React.FormEvent, text: string, column: IColumnConfig): void => { + if (!IsValidDataType(column?.dataType, text)) { SetObjValues((ev.target as Element).id, text, false, `Data should be of type '${column.dataType}'`) return; } - + SetObjValues((ev.target as Element).id, ParseType(column.dataType, text)); }; @@ -67,18 +68,53 @@ const ColumnUpdateDialog = (props : Props) => { <> ); - const onSelectDate = (date: Date | null | undefined, item : any): void => { + const onSelectDate = (date: Date | null | undefined, item: any): void => { SetObjValues(item.key, date); }; - const onCellPickerTagListChanged = (cellPickerTagList: ITag[] | undefined, item : any) : void => { - if(cellPickerTagList && cellPickerTagList[0] && cellPickerTagList[0].name) + const onCellDateChange = (date: Date | null | undefined, item: IColumnConfig): void => { + let currentDate = getColumnValue(item); + + if (currentDate === undefined || currentDate === null) { + currentDate = date; + } else if (date !== null && date !== undefined) { + currentDate.setFullYear(date.getFullYear()); + currentDate.setMonth(date.getMonth()); + currentDate.setDate(date.getDate()); + } + + SetObjValues(item.key, currentDate); + }; + + const onCellTimeChange = (dateTime: Date | null | undefined, item: IColumnConfig): void => { + let currentDate = getColumnValue(item); + + if (currentDate === undefined || currentDate === null) { + currentDate = dateTime; + } else if (dateTime !== null && dateTime !== undefined) { + currentDate.setHours(dateTime.getHours()); + currentDate.setMinutes(dateTime.getMinutes()); + currentDate.setSeconds(dateTime.getSeconds()); + currentDate.setMilliseconds(dateTime.getMilliseconds()); + } + + SetObjValues(item.key, currentDate); + }; + + + const getColumnValue = (item: IColumnConfig) => { + return inputValue[item.key].value; + }; + + + const onCellPickerTagListChanged = (cellPickerTagList: ITag[] | undefined, item: any): void => { + if (cellPickerTagList && cellPickerTagList[0] && cellPickerTagList[0].name) SetObjValues(item.key, cellPickerTagList[0].name); else SetObjValues(item.key, ''); } - const onDropDownChange = (event: React.FormEvent, selectedDropdownItem: IDropdownOption | undefined, item : any): void => { + const onDropDownChange = (event: React.FormEvent, selectedDropdownItem: IDropdownOption | undefined, item: any): void => { SetObjValues(item.key, selectedDropdownItem?.text); } @@ -87,21 +123,21 @@ const ColumnUpdateDialog = (props : Props) => { }; const closeDialog = React.useCallback((): void => { - if(props.onDialogCancel){ + if (props.onDialogCancel) { props.onDialogCancel(); } - + setInputFieldContent(undefined) }, []); const saveDialog = (): void => { - if(props.onDialogSave){ - var inputValueTmp : any = {}; + if (props.onDialogSave) { + var inputValueTmp: any = {}; var objectKeys = Object.keys(inputValue); var BreakException = {}; - try{ + try { objectKeys.forEach((objKey) => { - if(inputValue[objKey]['isChanged']){ + if (inputValue[objKey]['isChanged']) { inputValueTmp[objKey] = inputValue[objKey]['value']; throw BreakException; } @@ -116,11 +152,11 @@ const ColumnUpdateDialog = (props : Props) => { setInputFieldContent(undefined); }; - const createDropDownOptions = () : IDropdownOption[] => { + const createDropDownOptions = (): IDropdownOption[] => { let dropdownOptions: IDropdownOption[] = []; props.columnConfigurationData.forEach((item, index) => { - if(item.editable == true){ - dropdownOptions.push({ key: item.key, text: item.text}); + if (item.editable == true) { + dropdownOptions.push({ key: item.key, text: item.text }); } }); @@ -129,10 +165,10 @@ const ColumnUpdateDialog = (props : Props) => { const options = createDropDownOptions(); - const GetInputFieldContent = () : JSX.Element => { + const GetInputFieldContent = (): JSX.Element => { var column = props.columnConfigurationData.filter(x => x.key == gridColumn); - if(column.length > 0){ - switch(column[0].inputType){ + if (column.length > 0) { + switch (column[0].inputType) { case EditControlType.Date: return ( { ariaLabel="Select a date" className={controlClass.inputClass} onSelectDate={(date) => onSelectDate(date, column[0])} - //value={new Date()} + //value={new Date()} />); + case EditControlType.DateTime: + return ( + + onCellDateChange(date, column[0])} + /> + { onCellTimeChange(time, column[0]) }} + /> + ) case EditControlType.Picker: return (
- onCellPickerTagListChanged(selectedItem, column[0])} pickerDescriptionOptions={column[0].pickerOptions?.pickerDescriptionOptions} - />
); + />); case EditControlType.DropDown: return ( { styles={textFieldStyles} onChange={(ev, text) => onTextUpdate(ev, text!, column[0])} value={inputValue[column[0].key].value || ''} - />); + />); default: return ( onTextUpdate(ev, text!,column[0])} + onChange={(ev, text) => onTextUpdate(ev, text!, column[0])} styles={textFieldStyles} id={column[0].key} value={inputValue[column[0].key].value || ''} @@ -189,8 +242,8 @@ const ColumnUpdateDialog = (props : Props) => { return (<>); } - - return( + + return (