Socket
Book a DemoInstallSign in
Socket

react-mvc-datatable

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mvc-datatable

A reusable MUI-based abstract datatable for React apps

2.0.0
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

react-mvc-datatable

React MVC Datatable

npm version license Jenkins Build issues stars minified + gzip

Intead of repetitve copy-paste I made myself a library that helps up to build pages that contains DataTable elements.

Install

npm i react-mvc-datatable

How-To

Create the needed entity that extends Entity

Example:


export interface User extends Entity {

    username?: string;
    email?: string;
    available?: boolean;

}

  • Create the page that extends DataTable

Example:


export default class MyDemoTable extends DataTable<User> {

    buildDialog(): DialogConfig<User> {
        return {
            title: (isEdit) => (isEdit ? "Edit User" : "Add User"),
            submitText: (isEdit) => (isEdit ? "Save Changes" : "Create User"),
            validate: (item) => {
                const errors: Record<string, string> = {};
                if (!item.email) errors.username = "The email is required"
                if (!item.available) errors.available = "The availability is required"
                return { isValid: Object.keys(errors).length === 0, errors };

            },
            fields: [
                {
                    name: "username",
                    label: "Username",
                    required: false,
                    autoFocus: false
                },

                {
                    name: "email",
                    label: "Email",
                    required: true,
                    autoFocus: false
                }

                {
                    name: "available",
                    label: "Is Available",
                    type: "checkbox",
                    required: true,
                    autoFocus: false
                }
            ]
        }
    }


    buildColumns(): GridColDef[] {
        return [
            {
                field: "username",
                headerName: "Username",
                flex: 1
            },

            {
                field: "email",
                headerName: "Email",
                flex: 1
            },
            {
                field: "actions",
                type: "actions",
                headerName: "Actions",
                width: 100,
                getActions: (params) => [
                    <GridActionsCellItem
                        icon={<EditIcon />}
                        label="Edit"
                        onClick={() => this.handleEdit(params.row)}
                    />,
                ],
            },
        ]
    }

    getConfig(): DataTableConfig<User> {
        return {
            title: 'Users',
            columns: this.buildColumns(),
            addButtonLabel: "Add new user",
            pageSizeOptions: [5, 10, 20, 100],
            defaultPageSize: 20,
            initialRows: [mockUser],
            dialogConfig: this.buildDialog()
        }
    }

    handleSubmit(item: User): Promise<void> {
        // Your save logic here - this would typically call an API
        return new Promise((resolver) => {
            setTimeout(() => {
                // ID exists, apply update operations
                if (item.id) {
                    console.log("Updating employee :", item);
                } else {
                    // ID does NOT exist, add new entry
                    console.log("Saving employee:", item);
                }
            })
        })
    }

}

export const mockUser: User = {
    id: 1,
    email: "user@info.com",
    username: "user",
    available: false
}

Next steps ?

✅ Start using it, give feedback! ✅ Contributions are welcome

📄 License

react-mvc-datatable is licensed under the MIT license. See the LICENSE file for details.

FAQs

Package last updated on 28 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.