npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mui-editable-table

v0.3.3

Published

Multi-row editable table using material-ui with redux

Downloads

88

Readme

mui-editable-table

Multi-row editable table using material-ui with redux

  • Requires react 15.3.0 and up

I've seen a few of these, including a great one by emkay (https://github.com/emkay/material-ui-table-edit), but unfortunately none quite gave me the functionality I wanted. I was looking for a table that:

  • was object driven
  • allowed me to edit the entire table in one go (say you have a record with a set of sub rules, such as a strategy configuration, your users might want to edit the whole thing in one go)
  • had the ability to reorder
  • returned me the entire modified dataset so I didn't have to maintain the state and mappings myself (becomes a lot more handy when you add in reordering and deletions)

Hopefully this one will give some of you some benefit with enough customisation to play with in your use cases.

I've also left in all the build/demo run code which I used from windows so hopefully other people won't have the same issues I did trying to get the bundling working for a new component.

Install

npm install mui-editable-table --save

Usage

Once installed, reference it and pass it the relevant fields. Take a look at the demo under the example folder, or for a quick read continue below or look at example/src/app/Demo.js.

First include it

import MuiEditableTable from "mui-editable-table";

Then in your code include it within a form like so

<MuiEditableTable
    colSpec={this.colSpec}
    containerStyle={{width: "500px"}}
    rowData={this.rowData}
    onChange={onChange}
    reorderable={true}
/>
  • colSpec - see below, config for each column
  • containerStyle (optional) - styling for the table container div
  • rowData - array of records that can be mapped (partially or fully) to the colSpec
  • onChange - event to trigger when any changes to the editable table occur, will receive entire data structure back each time
  • reorderable (optional) - if set to true, allows rows to be reordered on the table via the up/down arrows

The colSpec would look something like this:

const colSpec = [
    {title: 'Title', fieldName: 'title', inputType: "SelectField", selectOptions: ["Mr", "Mrs", "Miss", "Other"], width: 200, defaultValue: 'Mr'},
    {title: 'Name', fieldName: 'foreName', inputType: "TextField", width: 200},
    {title: 'Surname', fieldName: 'surname', inputType: "TextField", width: 200},
    {title: 'Maiden Name', fieldName: 'maidenName', inputType: "TextField", width: 200, isReadOnly: shouldBeReadOnly},
    {title: 'Employed', fieldName: 'employed', inputType: "Toggle", width: 200}
];
  • Title - the header column value
  • fieldName - the value from the rowData object that matches this column and will be used for its data
  • inputType - field type to render. Supported types: TextField, SelectField, Toggle (toggle only supports true/false values)
  • width - how wide your want the column to be
  • defaultValue (optional) - should you wish to default your field, say for a number field you might want to default to 0.0, or a country field to your default country, etc
  • selectOptions (SelectField only) - list of options for your select dropdown. Note it can be a list of strings, or a list of key->value pairs. For the latter you'll need to set them up like [{key: 'keyValue', value: 'displayValue'}]
  • isReadOnly (optional) - function to check if field should be read only for the given row

The rowData for the above colSpec could look something like this:

const rowData = [
    { title: 'Mr', foreName: 'John', surname: 'Smith', employed: true},
    { title: 'Miss', foreName: 'Emily', surname: 'Lockhart', employed: false},
    { title: 'Mrs', foreName: 'Marilyn', surname: 'Monroe', employed: true}
];

the onChange event would then give you the entire dataset back. you can log it or store it locally to use on the forms submit method:

const onChange = (dataTable) => {
    console.log(dataTable)
};