Comparing version 2.5.3 to 2.5.4
@@ -54,2 +54,4 @@ export var DataType; | ||
FilterOperatorName["Contains"] = "contains"; | ||
FilterOperatorName["IsEmpty"] = "IsEmpty"; | ||
FilterOperatorName["IsNotEmpty"] = "IsNotEmpty"; | ||
})(FilterOperatorName || (FilterOperatorName = {})); |
@@ -53,2 +53,4 @@ export enum DataType { | ||
Contains = 'contains', | ||
IsEmpty = 'IsEmpty', | ||
IsNotEmpty = 'IsNotEmpty', | ||
} |
{ | ||
"name": "ka-table", | ||
"version": "2.5.3", | ||
"version": "2.5.4", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "github:komarovalexander/ka-table", |
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/komarovalexander/ka-table/blob/master/LICENSE) | ||
[![npm version](https://img.shields.io/npm/v/ka-table.svg?style=flat-square)](https://www.npmjs.com/package/ka-table) | ||
[![Coverage Status](https://coveralls.io/repos/github/komarovalexander/ka-table/badge.svg?branch=master)](https://coveralls.io/github/komarovalexander/ka-table?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/komarovalexander/ka-table/badge.svg?branch=master&service=github)](https://coveralls.io/github/komarovalexander/ka-table?branch=master&service=github) | ||
[![Build Status](https://travis-ci.com/komarovalexander/ka-table.svg?token=9QUEx9r7MWqF44f9VDer&branch=master)](https://travis-ci.com/komarovalexander/ka-table) | ||
@@ -156,3 +156,3 @@ | ||
| field | <code>string</code> | Specifies the property of data's object which value will be used in column, if null value from key option will be used | | ||
| fieldParents | <code>string[]</code> | Array contains names of parents for specific field. I.e. to set field company.representative.name column's option should be { key: 'company.representative.name', field: 'name', fieldParents: ['company', 'representative'] } | | ||
| fieldParents | <code>string[]</code> | Array contains names of parents for specific field [Overview Demo](https://komarovalexander.github.io/ka-table/#/overview) | | ||
| format | [<code>FormatFunc</code>](#FormatFunc) | Returns formated cell string [Example](https://komarovalexander.github.io/ka-table/#/custom-cell) | | ||
@@ -159,0 +159,0 @@ | headCell | <code>HeaderCellFunc</code> | Returns a custom header cell [Custom Head Cell Example](https://komarovalexander.github.io/ka-table/#/custom-header-cell) | |
@@ -11,4 +11,13 @@ import defaultOptions from '../defaultOptions'; | ||
var filterFunction = function (item) { | ||
return c.search ? c.search(searchText, item, c) : initialData.indexOf(item) < 0 | ||
&& getValueByColumn(item, c).toString().toLowerCase().includes(searchText.toLowerCase()); | ||
if (c.search) { | ||
return c.search(searchText, item, c); | ||
} | ||
if (initialData.indexOf(item) >= 0) { | ||
return false; | ||
} | ||
var columnValue = getValueByColumn(item, c); | ||
if (columnValue == null) { | ||
return false; | ||
} | ||
return columnValue.toString().toLowerCase().includes(searchText.toLowerCase()); | ||
}; | ||
@@ -20,3 +29,5 @@ return initialData.concat(data.filter(filterFunction)); | ||
return columns.reduce(function (initialData, column) { | ||
if (isEmpty(column.filterRowValue)) { | ||
if (isEmpty(column.filterRowValue) | ||
&& column.filterRowOperator !== FilterOperatorName.IsEmpty | ||
&& column.filterRowOperator !== FilterOperatorName.IsNotEmpty) { | ||
return initialData; | ||
@@ -35,4 +46,4 @@ } | ||
if (column.dataType === DataType.Date) { | ||
fieldValue = new Date(fieldValue).setHours(0, 0, 0, 0); | ||
conditionValue = new Date(conditionValue).setHours(0, 0, 0, 0); | ||
fieldValue = fieldValue == null ? fieldValue : new Date(fieldValue).setHours(0, 0, 0, 0); | ||
conditionValue = conditionValue == null ? conditionValue : new Date(conditionValue).setHours(0, 0, 0, 0); | ||
} | ||
@@ -75,6 +86,16 @@ return compare(fieldValue, conditionValue); | ||
compare: function (fieldValue, conditionValue) { | ||
return fieldValue.toString().toLowerCase().includes(conditionValue.toString().toLowerCase()); | ||
return fieldValue != null && fieldValue.toString().toLowerCase().includes(conditionValue.toString().toLowerCase()); | ||
}, | ||
defaultForTypes: [DataType.String], | ||
name: FilterOperatorName.Contains, | ||
}, { | ||
compare: function (fieldValue) { | ||
return isEmpty(fieldValue); | ||
}, | ||
name: FilterOperatorName.IsEmpty, | ||
}, { | ||
compare: function (fieldValue) { | ||
return !isEmpty(fieldValue); | ||
}, | ||
name: FilterOperatorName.IsNotEmpty, | ||
}]; |
@@ -16,4 +16,13 @@ import defaultOptions from '../defaultOptions'; | ||
const filterFunction = (item: any) => { | ||
return c.search ? c.search(searchText, item, c) : initialData.indexOf(item) < 0 | ||
&& getValueByColumn(item, c).toString().toLowerCase().includes(searchText.toLowerCase()); | ||
if (c.search) { | ||
return c.search(searchText, item, c); | ||
} | ||
if (initialData.indexOf(item) >= 0) { | ||
return false; | ||
} | ||
const columnValue = getValueByColumn(item, c); | ||
if (columnValue == null) { | ||
return false; | ||
} | ||
return columnValue.toString().toLowerCase().includes(searchText.toLowerCase()); | ||
}; | ||
@@ -26,3 +35,9 @@ return initialData.concat(data.filter(filterFunction)); | ||
return columns.reduce((initialData, column) => { | ||
if (isEmpty(column.filterRowValue)) { return initialData; } | ||
if ( | ||
isEmpty(column.filterRowValue) | ||
&& column.filterRowOperator !== FilterOperatorName.IsEmpty | ||
&& column.filterRowOperator !== FilterOperatorName.IsNotEmpty | ||
) { | ||
return initialData; | ||
} | ||
const filterRowOperator = column.filterRowOperator | ||
@@ -39,4 +54,4 @@ || getDefaultOperatorForType(column.dataType || defaultOptions.columnDataType); | ||
if (column.dataType === DataType.Date) { | ||
fieldValue = new Date(fieldValue).setHours(0, 0, 0, 0); | ||
conditionValue = new Date(conditionValue).setHours(0, 0, 0, 0); | ||
fieldValue = fieldValue == null ? fieldValue : new Date(fieldValue).setHours(0, 0, 0, 0); | ||
conditionValue = conditionValue == null ? conditionValue : new Date(conditionValue).setHours(0, 0, 0, 0); | ||
} | ||
@@ -76,5 +91,13 @@ return compare(fieldValue, conditionValue); | ||
compare: (fieldValue: any, conditionValue: any) => | ||
fieldValue.toString().toLowerCase().includes(conditionValue.toString().toLowerCase()), | ||
fieldValue != null && fieldValue.toString().toLowerCase().includes(conditionValue.toString().toLowerCase()), | ||
defaultForTypes: [DataType.String], | ||
name: FilterOperatorName.Contains, | ||
}, { | ||
compare: (fieldValue: any) => | ||
isEmpty(fieldValue), | ||
name: FilterOperatorName.IsEmpty, | ||
}, { | ||
compare: (fieldValue: any) => | ||
!isEmpty(fieldValue), | ||
name: FilterOperatorName.IsNotEmpty, | ||
}]; |
@@ -15,7 +15,38 @@ var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
} | ||
var sortFunc = sortedColumn.sortDirection === SortDirection.Ascend ? | ||
(function (a, b) { return getValueByColumn(a, sortedColumn) < getValueByColumn(b, sortedColumn) ? -1 : 1; }) | ||
: (function (a, b) { return getValueByColumn(a, sortedColumn) > getValueByColumn(b, sortedColumn) ? -1 : 1; }); | ||
var sortFunc = sortedColumn.sortDirection === SortDirection.Ascend | ||
? ascendSort(sortedColumn) : descendSort(sortedColumn); | ||
var newData = __spreadArrays(data).sort(sortFunc); | ||
return newData; | ||
}; | ||
export var ascendSort = function (sortedColumn) { | ||
return function (a, b) { | ||
var aValue = getValueByColumn(a, sortedColumn); | ||
var bValue = getValueByColumn(b, sortedColumn); | ||
if (aValue === bValue) { | ||
return 0; | ||
} | ||
else if (aValue == null) { | ||
return -1; | ||
} | ||
else if (bValue == null) { | ||
return 1; | ||
} | ||
return aValue < bValue ? -1 : 1; | ||
}; | ||
}; | ||
export var descendSort = function (sortedColumn) { | ||
return function (a, b) { | ||
var aValue = getValueByColumn(a, sortedColumn); | ||
var bValue = getValueByColumn(b, sortedColumn); | ||
if (aValue === bValue) { | ||
return 0; | ||
} | ||
else if (aValue == null) { | ||
return 1; | ||
} | ||
else if (bValue == null) { | ||
return -1; | ||
} | ||
return aValue > bValue ? -1 : 1; | ||
}; | ||
}; |
@@ -8,7 +8,36 @@ import { SortDirection } from '../enums'; | ||
if (!sortedColumn) { return data; } | ||
const sortFunc = sortedColumn.sortDirection === SortDirection.Ascend ? | ||
((a: any, b: any) => getValueByColumn(a, sortedColumn) < getValueByColumn(b, sortedColumn) ? -1 : 1) | ||
: ((a: any, b: any) => getValueByColumn(a, sortedColumn) > getValueByColumn(b, sortedColumn) ? -1 : 1); | ||
const sortFunc = sortedColumn.sortDirection === SortDirection.Ascend | ||
? ascendSort(sortedColumn) : descendSort(sortedColumn); | ||
const newData = [...data].sort(sortFunc); | ||
return newData; | ||
}; | ||
export const ascendSort = (sortedColumn: Column) => { | ||
return (a: any, b: any) => { | ||
const aValue = getValueByColumn(a, sortedColumn); | ||
const bValue = getValueByColumn(b, sortedColumn); | ||
if (aValue === bValue) { | ||
return 0; | ||
} else if (aValue == null) { | ||
return -1; | ||
} else if (bValue == null) { | ||
return 1; | ||
} | ||
return aValue < bValue ? -1 : 1; | ||
}; | ||
}; | ||
export const descendSort = (sortedColumn: Column) => { | ||
return (a: any, b: any) => { | ||
const aValue = getValueByColumn(a, sortedColumn); | ||
const bValue = getValueByColumn(b, sortedColumn); | ||
if (aValue === bValue) { | ||
return 0; | ||
} else if (aValue == null) { | ||
return 1; | ||
} else if (bValue == null) { | ||
return -1; | ||
} | ||
return aValue > bValue ? -1 : 1; | ||
}; | ||
}; |
203560
3517