Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ka-table

Package Overview
Dependencies
Maintainers
1
Versions
194
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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)

  • 1.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.9K
increased by92.83%
Maintainers
1
Weekly downloads
 
Created
Source

GitHub license npm version Build Status

Overview

The customizable, extendable, lightweight and free React Table Component

Table Demo link

Installation

npm

npm install ka-table

yarn

yarn add ka-table

Usage

Basic example

import React, { useState } from 'react';

import { ITableOption, Table } from 'ka-table';
import { DataType, SortDirection, SortingMode } from 'ka-table/enums';
import { OptionChangeFunc } from 'ka-table/types';

const dataArray: any[] = [
  { id: 1, name: 'Mike Wazowski', score: 80, passed: true },
  { id: 2, name: 'Billi Bob', score: 55, passed: false },
  { id: 3, name: 'Tom Williams', score: 45, passed: false },
  { id: 4, name: 'Kurt Cobain', score: 75, passed: true },
  { id: 5, name: 'Marshall Bruce', score: 77, passed: true },
  { id: 6, name: 'Sunny Fox', score: 33, passed: false },
];

const tableOption: ITableOption = {
  columns: [
    {
      dataType: DataType.String,
      key: 'name',
      sortDirection: SortDirection.Descend,
      style: { width: '33%' },
      title: 'Name',
    },
    { key: 'score', title: 'Score', style: { width: '10%' }, dataType: DataType.Number },
    { key: 'passed', title: 'Passed', dataType: DataType.Boolean },
  ],
  rowKeyField: 'id',
  sortingMode: SortingMode.Single,
};

const SortingDemo: React.FC = () => {
  const [option, changeOptions] = useState(tableOption);
  const onOptionChange: OptionChangeFunc = (value) => {
    changeOptions({...option, ...value });
  };
  return (
    <Table
      {...option}
      data={dataArray}
      onOptionChange={onOptionChange}
    />
  );
};

export default SortingDemo;

Demo link

Examples

Command Column - Functional columns which are not bound to data and used to add custom command to table

Custom Cell - Best way to customise look of every column in table

Custom DataRow - Customise look of a row in the table

Custom Editor - Table supports user created editors

Custom Header Cell - Customisation of header cell

Editing - Editing out of the box

Events - Most events are trackable

Filter Extended - Easy filtered by extended filters

Filter Row - Built-in filter row

Filter Row - Custom Editor - Customise filter cell every way you want

Grouping - Group data for most convenient work with it

25000 Rows - Virtualisation are supported

10000 Grouped Rows - Virtualisation work well with grouping

Search - Search by the whole Table is easy

Selection - Select and process specific rows

Sorting

State Storing - Save Table's state and restore it after page reload

Validation

API

Table

Properties

NameTypeDescription
columnsColumn[]Columns in table and their look and behaviour
dataany[]The Table's data
dataRowDataRowFuncReturns Data Row Template [Custom Data Row Example](https://komarovalexander.github.io/ka-table/#/custom-data-row
editableCellsCell[]Array of cells that are in edit mode Editing Example
editingModeEditingModeSets the table's editing mode Editing Example
filterRowFilterCondition[]Sets filters for columns Filter Row Example
groupsGroup[]Group's in the table Grouping Example
onDataChange(data: any[]) => voidThis function is called each time when data going to change, use it to override current data Editing Example
onOptionChange(value: any) => voidThis is mandatory function, this executes each time when grid going to change its state, use it to override current state Example
onEvent(type: string, data: any) => voidUse this function to track events in Table Events Example
groupsExpandedany[][]Groups that are expanded in the grid
rowKeyFieldstringData's field which is used to identify row
search stringSpecifies the text which are used for search by data Search Example
selectedRowsany[]Array of rows keys which are marked as selected Selection Example
sortingModeSortingModeSorting mode Sorting Example
virtualScrollingVirtualScrollingVirtual scrolling options - set it as empty object {} to enable virtual scrolling and auto calculate its parameters Many Rows Example

Column

Describes column of table its look and behaviour Properties

NameTypeDescription
cellCellFuncReturns a custom cell if Table is not in editable mode Custom Cell
dataTypeDataTypeSpecifies the type of column
editorEditorFuncReturns an editor if cell is in editable mode Custom Editor Example
filterCellEditorFuncReturns an editor for filter row cell Filter Row Custom Editor
fieldstringSpecifies the property of data's object which value will be used in column, if null value from key option will be used
formatFormatFuncReturns formated cell string Example
headCellHeaderCellFuncReturns a custom header cell Custom Head Cell Example
isEditablebooleanSpecifies can column be editable or not
keystringMandatory field, specifies unique key for the column
searchSearchFuncOverrides the default search method for the cell. Executes if Table.search option is set
sortDirectionSortDirectionSets the direction of sorting for the column
styleReact.CSSPropertiesSets the style options of the elements
titlestringSpecifies the text of the header
validationValidationFuncReturns the validation error string or does not return anything in case of passed validation Validation Example

Cell

Describes the position of a cell in the table

Properties

NameTypeDescription
fieldstringThe field of specific column
rowKeyValueanyData's key value of every specific row

FilterCondition

Properties

NameTypeDescription
fieldstringThe filtered column's field
operatorstringOperator which will be applied for filtering
valueanyFiltered value

Group

Properties

NameTypeDescription
fieldstringThe grouped column's field

VirtualScrolling

Properties

NameTypeDescription
scrollPositionnumberCurrent scroll top position
itemHeight((data: any) => number) | numberReturns height of specific row
tbodyHeightnumbertbody height

DataType

PropertyString value
Boolean'boolean'
Date'date'
Number'number'
Object'object'
String'string'

EditingMode

PropertyString valueDescription
None'none'Editing is disabled
Cell'cell'Data is edited by cell to cell, click by cell activates editing

SortDirection

PropertyString value
Ascend'ascend'
Descend'descend'

SortingMode

PropertyString value
None'none'
Single'single'

CellFunc

(props: ICellContentProps) => any;

Function which obtains ICellContentProps as parameter and returns React component which should be shown instead of cell content.

DataRowFunc

(props: IDataRowProps) => any;

Function which obtains IDataRowProps as parameter and returns React component which should be shown instead of Row content.

EditorFunc

(props: ICellEditorProps) => any;

Function which obtains ICellEditorProps as parameter and returns React component which should be shown instead of default editor.

FormatFunc

(value: any) => any;

Function which obtains value as parameter and returns formated value which will be shown in cell.

SearchFunc

(searchText?: string, rowData?: any, column?: Column) => boolean;

Function which obtains searchText?: string, rowData?: any, column?: Column - as parameters and returns boolean value which is true if cell's value is matched with searched value and false otherwise.

ValidationFunc

(value: any, rowData: any) => string | void;

Function which obtains value of specific cell and row - as parameters and returns validation error string or does not return anything in case of passed validation.

ICellEditorProps

Properties

NameTypeDescription
columnColumnsettings of the column in which editor is shown
rowDataanydata of the row in which editor is shown
close() => voidcall this method to close editor
onValueChange(newValue: any) => voidcall this method to change value of the row: onValueChange({ ...rowData, ...{ [field]: value } })

ICellEditorProps

Properties

NameTypeDescription
columnColumnsettings of the column in which editor is shown
openEditor() => voidcall this method to open editor of the cell
rowDataanydata of the row in which editor is shown

IDataRowProps

Properties

NameTypeDescription
columnsColumn[]Columns in table and their look and behaviour
dispatch(type: string, data: any) => voidExecutes specific event with specific data
editableCellsCell[]Array of cells that are in edit mode
editingModeEditingModeTable's editing mode
rowDataanyData of current row
isSelectedRowbooleanDescribes selected state of current row
rowKeyFieldstringData's field which is used to identify row
selectedRowsany[]Array of rows keys which are marked as selected

Keywords

FAQs

Package last updated on 27 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc