0.1.12 • Published 10 months ago

reactjs-server-side-table v0.1.12

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

ReactJs Server Side Table

A React module that can be used for rendering tables with dynamically paginated data.

Quick Features

  • Dynamic pagination
  • Sorting by columns
  • Searching
  • Language support (Currently -> English and Turkish)
  • Styless design. You can style the table as you like

Installation

npm install reactjs-server-side-table

API

OptionDescriptionRequiredDefault Value
tableColumnsColumns of the table. Must be same format with the example code. Since this module uses react-table as a base package, for more advance usage, you can check out the react-table docs and use the column properties there.true-
tableDataArray of data that is currently displayed on the table.true-
totalDataCountTotal data count that table will be displayed on the all pages. This is used for arranging pagination.true-
pageSizesArray of how many data will be displayed on a page. You can switch between the numbers for changing how many data will be displayed on a page.false10, 20, 30, 40, 50
defaultSortByInitial sorting column and direction value.falseFirst column - ascending order
getTableInfoOption for returning current table information, such as: pageIndex, pageSize, searchText, sortBy, sortDir. You can get the table's current information and get data according to this information.--
languageLanguage of the table. Supports: "tr" for Turkish and "en" for English.falseen
tableStyleInline style for table's <table> tagfalse-
theadStyleInline style for table's <thead> tagfalse-
thStyleInline style for table's <th> tagfalse-
tbodyStyleInline style for table's <tbody> tagfalse-
trStyleInline style for table's <tr> tagfalse-
tdStyleInline style for table's <td> tagfalse-

Sample Code

NOTE: Column accessor values must match with keys from the elements of the data. For example if accessor value is ticket_id, then data should be [{ticket_id: 1, ...etc}, ...etc]

For more information about columns: React-Table

import React, { useEffect, useState } from 'react';
import ServerSideTable from 'reactjs-server-side-table';

  function App() {
    const columns =  [
        {
          Header: "Ticket No",
          accessor: 'ticket_id'
        },
        {
          Header: `Reference`,
          accessor: 'reference',
          Cell: ({ row: { original } }) => (
            <div>
                {original.reference ? original.reference : '-'}
            </div>
          )
        }
      ]

    const [ticketList, setTicketList] = useState([]);
    const [ticketCount, setTicketCount] = useState(0);
    const [tableInfo, setTableInfo] = useState({});

    useEffect(() => {
  
      fetchTickets();
  
    }, [tableInfo]);

    const fetchTickets = () => {
        //fetch new data with tableInfo state
    }

    return (
      <div>
        {
          ticketList.length > 0 && ticketCount > 0 ? 
  
            <ServerSideTable
            tableColumns={columns}
            tableData={ticketList}
            totalDataCount={ticketCount}
            pageSizes={[10, 50, 100]}
            defaultSortBy={[{id: 'ticket_id', desc: true}]}
            getTableInfo={info => setTableInfo(info)}
            tableStyle={{backgroundColor: "#bbbbbb"}}
            language='en'
            />
    
            : <></>
  
        }

      </div>
    );

  }

You can fetch your data with the current tableInfo state from your server.

Table Information

tableInfo state returns this:

{sortBy: 'ticket_id', sortDir: 'desc', pageIndex: 3, pageSize: 10, searchText: '2'}

totalDataCount = 41

for a table like this:

table

0.1.12

10 months ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago