1.0.53 • Published 10 months ago

prototable v1.0.53

Weekly downloads
-
License
Proto Yazılım
Repository
-
Last release
10 months ago

A simple and powerful Datatable for React based.

Demo and documentation

Prerequisites

Installation

1.Install package

To install prototable with npm:

npm install prototable classnames date-fns --save

Usage

Here is a basic example of using prototable within a react application.

import React, { useEffect } from "react";
import "./styles.css";
import ProtoTable from "prototable";
import "prototable/index.css";
import mockedData from "./mockdata";

const selectOptions = [
  { value: "E", label: "Evet Evet Evet Evet Evet Evet Evet" },
  { value: "H", label: "Hayır" }
];

const gridOptions = {
  title: "Sample Data Grid",
  noData: {
    // icon: <div></div>,
    title: "No DATA"
  },
  deletable: {
    message: "Are you sure you want to delete this row?",
    onRowDeleteCancel: (row: any) =>
      new Promise((resolve, reject) => {
        resolve(true);
      }),
    onRowDelete: (row: any) =>
      new Promise((resolve, reject) => {
        resolve(true);
      })
  },
  editable: {
    onRowUpdate: (row: any) =>
      new Promise((resolve, reject) => {
        resolve(true);
      }),

    onRowUpdateCancel: (row: any) =>
      new Promise((resolve, reject) => {
        resolve(true);
      })
  },
  pagination: {
    pageable: true,
    pageSize: 10,
    onPageChanged: (pageNumber: number) => {
      console.log(pageNumber)
    }
  },
  selection: {
    multiSelect: true,
    onSelectionChange: (row: any) => {
      console.log(JSON.stringify(row));
    }
  },
  onRowSelection: (row: any) => {
    console.log("onRowSelection", row);
  },
  actions: [
    {
      title: 'Delete',
      icon: "Sil",
      onClick: (row: any, id: number) => {
        let dataArray = dataTable.getDataArray()
        dataArray.splice(id, 1)
        dataTable.loadWithDataArray(dataArray)
      }
    },
  ],
  detail: {
    title: ' ',
    render: (row: any) => {
      return <p>{row.id}</p>
    }
  },
  columns: [
    {
      title: "Company Code",
      prop: "kurumKod",
      filterable: true,
      style: { textAlign: "left", paddingLeft: 10, width: 100 },
      validation: (row: any, rawValue: any) => {
        const toNumbered = !isNaN(rawValue) && !isNaN(parseFloat(rawValue));
        const isValid = toNumbered ? null : "Validation message is here";
        return isValid;
      },
      editable: true
    },
    {
      title: "Company Name",
      prop: "kurumAd",
      filterable: true
    },
    {
      title: "Account No",
      prop: "hesapNo",
      sortable: false
    },
    {
      title: "Type",
      prop: "sozlesmeTuru"
    },
    {
      title: "Status",
      prop: "durum",
      filterable: true,
      validation: (row: any, rawValue: any) => {
        const toNumbered = !isNaN(rawValue) && !isNaN(parseFloat(rawValue));
        const isValid = toNumbered ? null : "Validation message is here";
        return isValid;
      },
      render: (rawValue: any, row: any, idx: number, length: number) => {
        return selectOptions.find((o) => o.value === rawValue)?.label;
      },
      editable: {
        type: "SELECT",
        selectOptions: selectOptions
      }
    },
    {
      title: "Account Opening Time",
      prop: "date"
    },
    {
      title: "Ratio",
      prop: "ratio",
      editable: true,
      validation: (row: any, rawValue: any) => {
        const toNumbered = !isNaN(rawValue) && !isNaN(parseFloat(rawValue)); 
        const isValid = toNumbered ? null : "Validation message is here";
        return isValid;
      }
    }
  ]
};
export default function App() {
  useEffect(() => {
    dataTable.loadWithDataArray(mockedData);
  });
  return (
    <div className="App">
      <h1>Hello EveryOne</h1>
      <ProtoTable
        ref={(table: any) => (dataTable = table)}
        buildRowOptions={(row: any, rowId: number) => {
          return {
            className: "customClassName",
            style: {
              height: 50,
              // backgroundColor: rowId % 2 === 0 ? 'gray' : 'white'
            }
          };
        }}
        gridOptions={gridOptions}
      />
    </div>
  );
}

License

This project is licensed under the terms of the MIT license.

1.0.48

12 months ago

1.0.49

12 months ago

1.0.51

12 months ago

1.0.50

12 months ago

1.0.53

10 months ago

1.0.52

11 months ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.30

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.0

4 years ago