0.2.0 • Published 10 months ago

yaa-grid v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

YAA Grid

YAA Grid control is a powerful and flexible tool for displaying and manipulating data. Specify your datasource and field names and you're ready to go. The Grid also offers support for features such as sorting, filtering, paging. These features allow you to easily manipulate and present large datasets in an efficient and user-friendly way.

PS this package is under development, please contact me for additional features

Screenshot

Changelog

  • Theme color customization by passing color prop e.g. color="red", color="#406882"
  • Images support are now added you just need to specify its type as below

    { field: 'thumbnail', header: 'Thumbnail', type: 'img', width: '100' },
  • Striped table view

  • Custom actions icons

Setup

To install the Grid and its dependent packages, use the following command.

npm install yaa-grid # or yarn add

import "yaa-grid/dist/style.css";

Using the library

Now it’s time to cover use cases. Starting from its basic form.

import { Grid } from 'yaa-grid';

import 'yaa-grid/dist/style.css';

const App: React.FC = () => {
  const [data, setData] = React.useState();
  const [loading, setLoading] = React.useState(false);
  const [pageNumber, setPageNumber] = React.useState(1);

  React.useEffect(() => {
    const fetchData = async () => {
      setLoading(true);
      const data = await fetch(`https://dummyjson.com/products?skip=${(pageNumber - 1) * 10}&limit=10`);

      const result = await data.json();

      setData(result);
      setLoading(false);
    };

    fetchData();
  }, [pageNumber]);

  /*
   * Column width is measured by pixels
   */
  const columns = [
    { field: 'id', header: 'ID', width: '50' },
    { field: 'brand', header: 'Brand', width: '100' },
    { field: 'category', header: 'Category', width: '100' },
    { field: 'description', header: 'Description', width: '200' },
    { field: 'price', header: 'Price', width: '100' },
    { field: 'rating', header: 'Rating', width: '100' },
    { field: 'title', header: 'Title', width: '100' },
    { field: 'thumbnail', header: 'Thumbnail', type: 'img', width: '100' },
  ];

  const onView = (e: string) => alert(`View ${e}`);
  const onEdit = () => alert('edit');
  const onDelete = () => alert('delete');

  return (
    <Grid
      rtl={false}
      // variant="stipe"
      search={false}
      jsonExport={false}
      data={data?.products}
      onView={onView}
      onEdit={onEdit}
      onDelete={onDelete}
      loading={loading}
      columns={columns}
      pageSize={10}
      pageNumber={pageNumber}
      totalRecords={data?.total}
      setPageNumber={setPageNumber}
      onSelect={(ids: any) => alert(ids)}
    />
  );
};

Props

NameTypeDescription
dataanyData source
colorstringe.g. "red" or "#406882"
columns{ field: string; header: string; width: string }[]columns data shape
variantstringstripe
heightstringSet the grid height
rtlbooleanRTL support for arabic
searchbooleandisplay search input
jsonExportbooleandisplay export option
loadingbooleandefaultValue: false
pageNumbernumberdefaultValue: 1
totalRecordsnumberused only with frontend pagination.
viewIconReactNode
editIconReactNode
deleteIconReactNode
onView(id: string) => void
onEdit(id: string) => void
onDelete(id: string) => void
onSelect(ids: string[]) => voidPerform action on selected records
setPageNumberReact.Dispatch<React.SetStateAction>Pagination

Contact

Please contact me for adding more features or package ideas

0.1.50

11 months ago

0.1.49

11 months ago

0.1.41

11 months ago

0.1.42

11 months ago

0.1.43

11 months ago

0.1.44

11 months ago

0.1.45

11 months ago

0.1.46

11 months ago

0.1.47

11 months ago

0.1.48

11 months ago

0.1.40

11 months ago

0.1.38

11 months ago

0.1.39

11 months ago

0.1.37

11 months ago

0.2.0

10 months ago

0.1.30

1 year ago

0.1.31

1 year ago

0.1.32

1 year ago

0.1.33

1 year ago

0.1.34

1 year ago

0.1.35

1 year ago

0.1.36

1 year ago

0.1.14

1 year ago

0.1.15

1 year ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.29

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.25

1 year ago

0.1.26

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.13

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

2 years ago