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

customize-data-grid

v1.0.5

Published

Quickly Create Drag And Drop Tables With The Power Of Material UI Data Grid Table

Downloads

20

Readme

Customize Data Grid

Quickly Create Drag And Drop Tables With The Power Of Material UI Data Grid Table 🎉✌️

Getting Started

Please follow the step-by-step guide below.

Installation

Before installing customize-data-grid make sure you have already installed all Material Ui all dependencies:

  npm install @mui/material @emotion/react @emotion/styled @mui/icons-material @mui/x-data-grid 
  or
  yarn add @mui/material @emotion/react @emotion/styled @mui/icons-material @mui/x-data-grid

Install customize-data-grid with npm or yarn

  npm i customize-data-grid
  or
  yarn add customize-data-grid

Usage/Examples

Basic Usage:

import React, { useState } from "react";
import { CustomizeDataGrid, useRowDragging } from "customize-data-grid";

const columns = [
  { field: "id", headerName: "ID", width: 90 },
  {
    field: "firstName",
    headerName: "First name",
    width: 150,
    editable: true,
  },
  {
    field: "lastName",
    headerName: "Last name",
    width: 150,
    editable: true,
  },
  {
    field: "fullName",
    headerName: "Full name",
    description: "This column has a value getter and is not sortable.",
    sortable: false,
    width: 160,
    valueGetter: (params) =>
      `${params.row.firstName || ""} ${params.row.lastName || ""}`,
  },
];

const rowsData = [
  { id: 1, lastName: "Snow", firstName: "Jon" },
  { id: 2, lastName: "Lannister", firstName: "Cersei" },
  { id: 3, lastName: "Lannister", firstName: "Jaime" },
  { id: 4, lastName: "Stark", firstName: "Arya" },
  { id: 5, lastName: "Targaryen", firstName: "Daenerys" },
];

const App = () => {
  const [rows, setRows] = useState(rowsData);
  const { DragableRows } = useRowDragging(rows, setRows);

  return (
    <>
      <CustomizeDataGrid
        rows={rows}
        columns={columns}
        initialState={{
          pagination: {
            paginationModel: {
              pageSize: 5,
            },
          },
        }}
        pageSizeOptions={[5, 10, 25, 50, 100]}
        dragableRowsIcon
        slots={{
          cell: DragableRows(),
        }}
      />
    </>
  );
};

export default App;

Full Usage:

import React, { useState } from "react";
import { CustomizeDataGrid, useRowDragging } from "customize-data-grid";

const columns = [
  { field: "id", headerName: "ID", width: 90 },
  {
    field: "firstName",
    headerName: "First name",
    width: 150,
    editable: true,
  },
  {
    field: "lastName",
    headerName: "Last name",
    width: 150,
    editable: true,
  },
  {
    field: "fullName",
    headerName: "Full name",
    description: "This column has a value getter and is not sortable.",
    sortable: false,
    width: 160,
    valueGetter: (params) =>
      `${params.row.firstName || ""} ${params.row.lastName || ""}`,
  },
];

const rowsData = [
  { id: 1, lastName: "Snow", firstName: "Jon" },
  { id: 2, lastName: "Lannister", firstName: "Cersei" },
  { id: 3, lastName: "Lannister", firstName: "Jaime" },
  { id: 4, lastName: "Stark", firstName: "Arya" },
  { id: 5, lastName: "Targaryen", firstName: "Daenerys" },
];

const App = () => {
  const [rows, setRows] = useState(rowsData);

  const apiCall = async (updatedRows, dragRow) => {
    try {
      // write your api or any custom logic here......
      console.log({ updatedRows, dragRow });
    } catch (err) {
      console.log(err, "------err");
    }
  };

  const { DragableRows } = useRowDragging(rows, setRows, apiCall);

  const callback = (colParams) => {
    console.log("colParams:", colParams);
    if (colParams?.hasFocus) {
      // custom logic here......
    }
  };

  return (
    <>
      <CustomizeDataGrid
        rows={rows}
        columns={columns}
        initialState={{
          pagination: {
            paginationModel: {
              pageSize: 5,
            },
          },
        }}
        pageSizeOptions={[5, 10, 25, 50, 100]}
        dragableRowsIcon
        slots={{
          cell: DragableRows(callback, {
            hasFocus: false,
            width: 120,
            //.....
          }),
        }}
      />
    </>
  );
};

export default App;

API Reference

dragableRowsIcon

CustomizeDataGrid props

| Parameter | Type | Default | Description | | :-------- | :------- | :------- | :-------------------------------- | | dragableRowsIcon | boolean |false | Required. for showing drag column with icon |

DragableRows(callback, colProps)

CustomizeDataGrid function use for drag and drop functionality

| Parameter | Type | Default | Description | | :-------- | :------- | :------- | :-------------------------------- | | callback | function |null | Optional. for doing addtional functional with colParams provided by Material Ui | colProps | object |{} | Optional. for set the colParams props |

useRowDragging(rows, setRows, apiCall)

CustomizeDataGrid hook

| Parameter | Type | Default | Description | | :-------- | :------- | :------- | :-------------------------------- | | rows | array |any | Required. render rows on the table. useState variable | setRows | function |any | Required. rows setter function. useState function | apiCall | function |any | Optional. for doing action when the dragging end

Badges

MIT License

License

MIT

🚀 About Me

I'm Amaan Ansari (Aman Asif), a Full Stack Developer. As a full-stack developer, I have 2+ years of experience. Among the technologies I am proficient in are ReactJS and NodeJS, as well as databases such as MongoDB and MySQL. My experience comes from managing projects, working with teams, and handling associate developers on multiple projects.

🔗 Links

linkedin twitter