Giter Club home page Giter Club logo

ashvin27 / react-datatable Goto Github PK

View Code? Open in Web Editor NEW
80.0 6.0 46.0 7.1 MB

React-datatable is a component which provide ability to create multifunctional table using single component like jQuery Datatable. It's fully customizable and easy to integrate in any react component. Bootstrap compatible.

License: MIT License

JavaScript 95.87% CSS 1.13% HTML 2.99%
datatables datatables-plugin react-table react-datagrid react-data-table react-datatable react data table

react-datatable's Introduction

react-datatable

npm version Known Vulnerabilities

ReactDatatable is a component which provide ability to create multifunctional table using single component like jQuery Datatable. It's fully customizable and easy to integrate in any react component. Bootstrap compatible.

Features

  • Lightweight
  • Fully customizable (JSX, templates, state, styles, callbacks)
  • Client-side & Server Side Pagination
  • Multi-sort
  • Filters
  • Minimal design
  • Fully controllable via optional props and callbacks

Example

http://react-datatable.in/

Installation

With npm installed, run

npm i @ashvin27/react-datatable

Usage

import React, { Component, Fragment } from 'react';
import { render} from 'react-dom';
import ReactDatatable from '@ashvin27/react-datatable';

class App extends Component {
    constructor(props) {
        super(props);
        this.columns = [
            {
                key: "name",
                text: "Name",
                className: "name",
                align: "left",
                sortable: true,
            },
            {
                key: "address",
                text: "Address",
                className: "address",
                align: "left",
                sortable: true
            },
            {
                key: "postcode",
                text: "Postcode",
                className: "postcode",
                sortable: true
            },
            {
                key: "rating",
                text: "Rating",
                className: "rating",
                align: "left",
                sortable: true
            },
            {
                key: "type_of_food",
                text: "Type of Food",
                className: "type_of_food",
                sortable: true,
                align: "left"
            },
            {
                key: "action",
                text: "Action",
                className: "action",
                width: 100,
                align: "left",
                sortable: false,
                cell: record => { 
                    return (
                        <Fragment>
                            <button
                                className="btn btn-primary btn-sm"
                                onClick={() => this.editRecord(record)}
                                style={{marginRight: '5px'}}>
                                <i className="fa fa-edit"></i>
                            </button>
                            <button 
                                className="btn btn-danger btn-sm" 
                                onClick={() => this.deleteRecord(record)}>
                                <i className="fa fa-trash"></i>
                            </button>
                        </Fragment>
                    );
                }
            }
        ];
        this.config = {
            page_size: 10,
            length_menu: [ 10, 20, 50 ],
            button: {
                excel: true,
                print: true,
                extra: true,
            }
        }
        
        this.state = {
            records: [
              {
                "id": "55f14312c7447c3da7051b26",
                "address": "228 City Road",
                "name": ".CN Chinese",
                "postcode": "3JH",
                "rating": 5,
                "type_of_food": "Chinese"
              },
              {
                "id": "55f14312c7447c3da7051b27",
                "address": "376 Rayleigh Road",
                "name": "@ Thai",
                "postcode": "5PT",
                "rating": 5.5,
                "type_of_food": "Thai"
              },
              {
                "id": "55f14312c7447c3da7051b28",
                "address": "30 Greyhound Road Hammersmith",
                "name": "@ Thai Restaurant",
                "postcode": "8NX",
                "rating": 4.5,
                "type_of_food": "Thai"
              },
              {
                "id": "55f14312c7447c3da7051b29",
                "address": "30 Greyhound Road Hammersmith",
                "name": "@ Thai Restaurant",
                "postcode": "8NX",
                "rating": 4.5,
                "type_of_food": "Thai"
              }
            ]
        }
        this.extraButtons =[
            {
                className:"btn btn-primary buttons-pdf",
                title:"Export TEst",
                children:[
                    <span>
                    <i className="glyphicon glyphicon-print fa fa-print" aria-hidden="true"></i>
                    </span>
                ],
                onClick:(event)=>{
                    console.log(event);
                },
            },
            {
                className:"btn btn-primary buttons-pdf",
                title:"Export TEst",
                children:[
                    <span>
                    <i className="glyphicon glyphicon-print fa fa-print" aria-hidden="true"></i>
                    </span>
                ],
                onClick:(event)=>{
                    console.log(event);
                },
                onDoubleClick:(event)=>{
                    console.log("doubleClick")
                }
            },
        ]
    }

    editRecord(record) {
        console.log("Edit Record", record);
    }

    deleteRecord(record) {
        console.log("Delete Record", record);
    }

    render() {
        return (
            <div>
                <ReactDatatable
                    config={this.config}
                    records={this.state.records}
                    columns={this.columns}
                    extraButtons={this.extraButtons}
                />
            </div>
        )
    }
}

render(<App />, document.getElementById("app"));

API

import ReactDatatable from '@ashvin27/react-datatable';
or
var ReactDatatable = require('@ashvin27/react-datatable')

Props

Name Type Description
className String Datatable additional class, use to appy additional styling on table
tHeadClassName String Additional class to be put on the "thead" of the table
columns Object[] This props will used to specify datatable column configuration
config Object[] This props will used to specify datatable configuration
dynamic boolean This props will used to specify the table data will be server side or static
id String Identifier of datatable
records Object[] This props will used to table records
total_record Number This props will used to specify the total records in case of table data is server side.
onChange Function(Object) This method will call on table actions(page change, sorting, filtering, page length change)
onRowClicked Function(Object) This method will call when user click on a row, return row object.
extraButtons Object[] This props will add custom extra buttons to the table tools in the top right of the table header next to the built in export buttons
onSort function(String, Object[], String) This props will allow you to sort your data/records using any custom sort function. Or according to you if you don't want to use default sort function provided by the Library.
loading Boolean(default false) This props will allow you to display a loading in table while data is fetching from the server.

Options

Name Type default Description
key_column string id Use to specify the key column name for each record
button Object[] { excel: false, print: false, csv: false } Use to enable/disable export buttons(Excel, CSV, Print). By default buttons are disabled.
filename String "table" Specify the export filename
length_menu Array[] [10, 25, 50, 75, 100] Specify the options in the page length select list.
page_size Number 10 Specify the page length (number of rows per page)
sort Object[] { column: "", order: "asc" } Initial sorting order to apply to the datatable
show_filter boolean true Use to specify either show or hide filter option
show_first boolean true Use to specify either show or hide pagination first button
show_info boolean true Use to specify either show or hide pagination info
show_last boolean true Use to specify either show or hide pagination last button
show_length_menu boolean true Use to specify either show or hide page length menu
show_pagination boolean true Use to specify either show or hide pagination
pagination string basic Use to specify the type of pagination. Available types: basic/advance

Columns

Name Type default Description
align String left Specify the content alignment
className String Table column additional class fo styling (only for data columns use TrOnlyClassName for headers)
TrOnlyClassName String Header column additional class ( only for headers ) WILL NOT automatically take className value if not set
key String Specify the key of record which value will display in table cell
sortable Boolean false Specify the column is sortable of not
text String Specify the table column text
width Number Specify the column width
cell Function(record, index):string You can use any react component or JSX to display content in cells

react-datatable's People

Contributors

androidneha avatar ashvin27 avatar ashvinpdigivalet avatar clu-sh avatar deewai avatar dependabot[bot] avatar felixkiss avatar harm-nullix avatar moda20 avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-datatable's Issues

Dealing The Big Data or paginate call

when we need to deal any big data, we call api for paginate.
like apicall?start_at=20&limitation=10

To use this plugin, I should load the whole data and load them at a once.
it make me to feel the website so slow.
Is there any way to call api for paginate?

React Javascript Warning

Hello,
Some functions gives an warning because of React's Warning: A future version of React will block javascript: URLs as a security precaution. Use event handlers instead if you can. If you need to generate unsafe HTML try using dangerouslySetInnerHTML instead. React was passed "javascript:void(0);

Thanks for great job.

EXPORT THE EXCEL

this is my table 1

I want to remove this column. What should I do?
2

Failed to Compile

./node_modules/@ashvin27/react-datatable/lib/up-arrow.png 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)

Bug on CSS

`./node_modules/@ashvin27/react-datatable/lib/style.css 1:12
Module parse failed: Unexpected token (1:12)
You may need an appropriate loader to handle this file type.

th.sortable {
| color: #2196F3;
| cursor: pointer;`

Each child in a list should have a unique "key" prop

Check the render method of ReactDatatable. See https://fb.me/react-warning-keys for more information.

in tr (created by ReactDatatable)
in ReactDatatable (at Users.js:140)
in div (at Users.js:137)
in div (at Users.js:136)
in div (at Users.js:134)
in div (at Users.js:132)
in Users (created by ConnectFunction)
in ConnectFunction (at PrivateRoute.js:11)
in Route (at PrivateRoute.js:7)
in PrivateRoute (created by ConnectFunction)
in ConnectFunction (at App.js:46)
in Switch (at App.js:44)
in Switch (at App.js:40)
in div (at App.js:39)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:38)
in Provider (at App.js:37)
in App (at src/index.js:7)

Because of this error search, pagination, sorting not working Kindly help me out

0 Int not renders

I find out that if we have 0 in one of column results then that 0 is not renders
Screenshot from 2021-02-08 20-27-30
Screenshot from 2021-02-09 00-40-32

Is that ok? or needs a fix?

csv

i can't the csv export functionality isn't working well is there a way to fix it

Support for Functional Components

Hi, thanks for the nice package.
Can this package be used with functional components? because I could not see an example in your docs. If it supports functional components, please update the docs

Custom Header and Footer

I would love to be able to add a footer so I can calculate totals without that item sorting.

It would also be great to be able to do a custom component/custom title for pdf print

print and export issue while searching

if i search some keyword and i got the result the searched, and now i am trying to print or export the data. It should only print or export the searched data not the whole data. please give me the suggestion i want to implement like the way.

Thank you :)

Nested json Data

Hey Ashvin27, am trying to read a nested json data, but can't seem to. please i do require your assistance.. Please do share any thoughts on this

CSV doesn't contain computed values

Hi Ashvin, great work here

Issue
CSV does not contain computed data

cell: record => ${record.lastName} ${record.firstName}

other values show up, but values that were computed via cell do not show up in csv or pdf, they do show up in the table though

Pagination for empty records

When there is an empty record, the pagination still enables next and last buttons. This shouldn't be so. All pagination buttons should be disabled for empty records.

React CSV download from Cell tag

Hi i am trying to export my table in CSV but whenever i try to export it only show the data not in cell tag so i wanna know is there is any way of doing it please help me
Thank You.

            {
                // key: "id",
                text: "S.No.",
                className: "id",
                align: "left",
                sortable: true,
                cell:(row, index)=>index+1
            },
            {
                key: "tx_id",
                text: "Transaction_id",
                className: "transaction_id",
                align: "left",
                sortable: true,
            },
            {
                key: "email",
                text: "Email",
                className: "email",
                align: "left",
                sortable: true,
            },
            

            {
                key: "amount",
                text: "Amount",
                className: "amount",
                align: "left",
                sortable: true,
                cell: record => {
                    return (
                        <span>
                            {Math.abs(record.coin_amount)}
                        </span>
                    );
                }
            },
            {
                key: "coinName",
                text: "	Cryptocoin",
                className: "coinName",
                align: "left",
                sortable: true,
                cell: record => {
                    return (
                        <span>
                        {record.coinName == undefined ?
                            (this.state.cryptoName):(record.coinName)
                        }
                        </span>
                    );
                }
            },
            // {
            //     key: "status",
            //     text: "Status",
            //     className: "status",
            //     align: "left",
            //     sortable: true
            // },
            {
                key: "created",
                text: "Date",
                className: "date",
                align: "left",
                sortable: true,
                cell: record => {
                    return (
                        <Fragment>
                            {Moment(record.created).format('lll')}
                        </Fragment>
                    );
                }
            },
]````

Rendering nested column data

When I am trying to render nested data, How should I need to provide "KEY" name ?

Example : If I have below data, How can I print name in single column ?

let data = [
{
id: 1,
userDetails : {
name : "vinod",
age : 23
}
}

{
id: 1,
userDetails : {
name : "kumar",
age : 22
}
}

]

Problem on changing the results per page when the user is in another pagination,

Hi There!

Thank you for doing this awesome project, I wanted to tell that I found a little issue when a user changes to watch all results in the list of the component only if the user is in another page, for example.

To reproduce:
Go to page 2 or 3 etc... and then select ALL results...
No results are found in the component...

if you please check it out. I'll be great
Thank you again and have a nice day

Eliminate y update row ?

Hi Ashvin, I'm trying to delete a row so that it disappears from the list without reloading but I don't know how to do it, I don't think it has it, but I wanted to ask you first to see if it is possible or should I try to modify the package.

image

image

Is this dead?

Is this project dead and if so, where is an updated datagrid for React? I started learning react and started using this last month, and running into some issues.

  • images not appearing on the export buttons
  • how to add a checkbox and or radio button in a cell
  • cell formatting based on data

If there is an updated version of this datagrid or if it's ghost now, can someone point me to a newer datagrid to use within React?

No example for Server-side pagination

Hi,
The library is nice. Easy to integrate. But could not find the server-side example of the implementation.
Please add it in the documentation.

Uncaught Error: Invariant failed: You should not use <Link> outside a <Router>

When I tried to download xls file by clicking export button its gives the error.

Uncaught Error: Invariant failed: You should not use <Link> outside a <Router>
    at invariant (tiny-invariant.esm.js:13)
    at Object.children (react-router-dom.js:147)
    at ReactDOMServerRenderer.render (react-dom-server.browser.development.js:3749)
    at ReactDOMServerRenderer.read (react-dom-server.browser.development.js:3453)
    at Object.renderToStaticMarkup (react-dom-server.browser.development.js:4086)
    at ReactDatatable.getExportHtml (index.js:377)
    at ReactDatatable.exportToExcel (index.js:414)
    at HTMLUnknownElement.callCallback (react-dom.development.js:363)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:412)
    at invokeGuardedCallback (react-dom.development.js:466)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:481)
    at executeDispatch (react-dom.development.js:614)
    at executeDispatchesInOrder (react-dom.development.js:639)
    at executeDispatchesAndRelease (react-dom.development.js:744)
    at executeDispatchesAndReleaseTopLevel (react-dom.development.js:753)
    at forEachAccumulated (react-dom.development.js:725)
    at runEventsInBatch (react-dom.development.js:770)
    at runExtractedPluginEventsInBatch (react-dom.development.js:916)
    at handleTopLevel (react-dom.development.js:6171)
    at batchedEventUpdates (react-dom.development.js:2422)
    at dispatchEventForPluginEventSystem (react-dom.development.js:6271)
    at dispatchEvent (react-dom.development.js:6301)
    at unstable_runWithPriority (scheduler.development.js:674)
    at runWithPriority$2 (react-dom.development.js:11834)
    at discreteUpdates$1 (react-dom.development.js:22935)
    at discreteUpdates (react-dom.development.js:2440)
    at dispatchDiscreteEvent (react-dom.development.js:6254)
  constructor(props) {
        super(props);

        this.columns = [
            {
                key: "course_name",
                text: "Course  Name", 
                sortable: true,
                width: 180,
                cell: (record, index) => {
                    return (
                        <Link to={{
                            pathname: `/updatecourseadmin`,
                            state: { 
                                course_id:  record.course_id,
                                course_auto_id:  record.id
                             
                            }
                        }} className="enquiryLink">{ record.course_name }</Link>
                    );
                }
            },
            {
                key: "institute_name",
                text: "Institute", 
                sortable: true,
                width: 150
            },
            {
                key: "course_category",
                text: "Category", 
                sortable: true,
                width: 150
            },
            {
                key: "approve",
                text: "Approve", 
                sortable: false,
                width: 130,
                cell: (record, index) => {
                    return (
                        <UnapproveChildApprove feature={record.id}  approved={record.approved}/>
                    );
                }
            }, 
            {
                key: "preview",
                text: "Preview", 
                sortable: false,
                width: 100,
                cell: (record, index) => {
                    return (  
                        <img src={api_server.base_url+"/"+record.image} style={{height:"50px","width":"80px"}} />
                    );
                }
            }
        ];
        this.config = {
            page_size: 10,
            length_menu: [10, 20, 50],
            show_filter: true,
            show_pagination: true,
            pagination: 'advance',
            filename: "approved_courses",
            button: {
                excel: true,
                print: true,
                csv: true
            }
        } 

Please help

Nested

Hi can't read some nested data from my json file. please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.