1.0.47 • Published 1 month ago

prototable v1.0.47

Weekly downloads
-
License
Proto Yazılım
Repository
-
Last release
1 month 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.47

1 month ago

1.0.46

2 months ago

1.0.45

2 months ago

1.0.44

3 months ago

1.0.43

4 months ago

1.0.42

4 months ago

1.0.41

4 months ago

1.0.39

4 months ago

1.0.38

4 months ago

1.0.40

4 months ago

1.0.37

5 months ago

1.0.36

5 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.31

7 months ago

1.0.35

5 months ago

1.0.34

7 months ago

1.0.30

8 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

12 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

10 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.29

8 months ago

1.0.28

8 months ago

1.0.27

9 months ago

1.0.15

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

3 years ago

1.0.0

3 years ago