Skip to content

Commit

Permalink
Merge pull request #404 from komarovalexander/dev
Browse files Browse the repository at this point in the history
Performance improvement: do not check every cell type while render
  • Loading branch information
komarovalexander authored Apr 28, 2024
2 parents 2d06994 + bda2eb7 commit cdb2234
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 182 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ka-table",
"version": "8.12.0",
"version": "9.0.0",
"license": "MIT",
"repository": "github:komarovalexander/ka-table",
"homepage": "https://komarovalexander.github.io/ka-table/#/overview",
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/CustomCellDemo/CustomCellDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const CustomCellDemo = () => {
return `$${value}`;
}
if (column.dataType === DataType.Date){
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
}
}}
data={dataArray}
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/CustomDataRowDemo/CustomDataRowDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CustomDataRowDemo = () => {
dataType: DataType.String,
key: 'name',
sortDirection: SortDirection.Descend,
width: 100,
width: 150,
title: 'Student',
},
{ key: 'score', title: 'Score', dataType: DataType.Number },
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/CustomEditorDemo/CustomEditorDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const CustomEditorDemo: React.FC = () => {
]}
format= {({ column, value }) => {
if (column.dataType === DataType.Date){
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
}
}}
data={dataArray}
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/EditingDemo/EditingDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const EditingDemo: React.FC = () => {
]}
format= {({ column, value }) => {
if (column.dataType === DataType.Date){
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
}
}}
data={dataArray}
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/HeaderFilterDemo/HeaderFilterDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const HeaderFilterDemo = () => {
filteringMode={FilteringMode.HeaderFilter}
format= {({ column, value }) => {
if (column.dataType === DataType.Date) {
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
}
}}
rowKeyField={'id'}
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/HeaderFilterLogicDemo/HeaderFilterLogicDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const HeaderFilterLogicDemo = () => {
filteringMode={FilteringMode.HeaderFilter}
format={({ column, value }) => {
if (column.dataType === DataType.Date) {
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
}
if (column.key === 'departments') {
return value?.map((d: any) => d.name).join(', ');
Expand Down
15 changes: 7 additions & 8 deletions src/Demos/HoverRowDemo/HoverRowDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ROW_MOUSE_LEAVE = 'ROW_MOUSE_LEAVE';


const HoverRowDemo = () => {
const [selectedItem] = useState<typeof dataArray[number]>();
const [hoveredItem, setHoveredItem] = useState<typeof dataArray[number]>();
return (
<div className='hover-row-demo'>
<Table
Expand Down Expand Up @@ -46,22 +46,21 @@ const HoverRowDemo = () => {
onMouseEnter: (event, extendedEvent) => {
const {
childProps: {
rowKeyValue,
rowData,
},
dispatch,
} = extendedEvent;
dispatch({ type: ROW_MOUSE_ENTER, rowKeyValue });
setHoveredItem(rowData);
},
onMouseLeave: (event, { dispatch }) => {
dispatch({ type: ROW_MOUSE_LEAVE });
onMouseLeave: () => {
setHoveredItem(undefined);
},
}),
}
}}
/>
{ selectedItem && (
{ hoveredItem && (
<div className='info'>
Hovered: {selectedItem.name} ({selectedItem.company.name})
Hovered: {hoveredItem.name} ({hoveredItem.company.name})
</div>
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/MaterialDemo/MaterialDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const MaterialDemo = () => {
]}
format={({ column, value }) => {
if (column.dataType === DataType.Date) {
return value && value.toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', { month: '2-digit', day: '2-digit', year: 'numeric' });
}
}}
paging={{
Expand Down
2 changes: 1 addition & 1 deletion src/Demos/NullableCellDataDemo/NullableCellDataDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const NullableCellDataDemo = () => {
return value == null ? '-' : `$${value}`;
}
if (column.dataType === DataType.Date){
return value && value.toLocaleDateString('en', {month: '2-digit', day: '2-digit', year: 'numeric' });
return value && new Date(value).toLocaleDateString('en', {month: '2-digit', day: '2-digit', year: 'numeric' });
}
}}
filteringMode={FilteringMode.FilterRow}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Components/Popup/Popup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const props: any = {
column: {key: 'field'},
childComponents: {},
dispatch: () => {},
data: [{ feild: 1 }]
data: [{ field: 1 }]
};

it('renders without crashing', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/lib/Utils/FilterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Column } from '../Models/Column';
import { EditableCell } from '../Models/EditableCell';
import { FilterOperator } from '../Models/FilterOperator';
import { ITableProps } from '../';
import { convertToColumnTypes } from './TypeUtils';
import defaultOptions from '../defaultOptions';
import { getValueByColumn } from './DataUtils';
import { isEmpty } from './CommonUtils';
Expand Down Expand Up @@ -50,7 +49,6 @@ export const filterAndSearchData = (props: ITableProps) => {
data = [...data];
data = extendedFilter ? extendedFilter(data) : data;
data = searchText ? searchData(columns, data, searchText, search) : data;
data = convertToColumnTypes(data, columns);
data = filterData(data, columns, filter);
data = filterByHeaderFilter(data, columns, format);

Expand Down
103 changes: 0 additions & 103 deletions src/lib/Utils/TypeUtils.test.ts

This file was deleted.

55 changes: 0 additions & 55 deletions src/lib/Utils/TypeUtils.ts

This file was deleted.

5 changes: 1 addition & 4 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@

import * as kaColumnUtils from './Utils/ColumnUtils';
import * as kaDateUtils from './Utils/DateUtils';
import * as kaPropsUtils from './Utils/PropsUtils';
import * as kaTypeUtils from './Utils/TypeUtils';
import * as kaPagingUtils from './Utils/PagingUtils';
import * as kaPropsUtils from './Utils/PropsUtils';

export {
kaColumnUtils,
kaDateUtils,
kaPropsUtils,
kaTypeUtils,
kaPagingUtils
};

0 comments on commit cdb2234

Please sign in to comment.