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

dynamic-muidatatable

v0.2.1

Published

Extension of MUI Datatables

Downloads

11

Readme

Dynamic MUI Table

Its designed to handle DJango generic class pagination api with filter, search and sorting functionality. This component have following features.

Note: Requires redux-axios-jwt npm package. Please set it up before using this.

This componenet is built upon MUI Datatable and Redux. MUI Datatable

  • Pagination
  • Sorting
  • Filter
  • Search
  • Download
  • New custom columns
  • Custom Actions

Sample code for DJango generic API

Following is a sample DJango DRF generic pagination api. For ref: Pagination - DRF

class VehiclePaginationView(generics.ListAPIView):
	authentication_classes = (authentication.JWTAuthentication,)
	permission_classes = [permissions.IsAuthenticated]

	queryset = vehicle.objects.filter(de_fleeted=False).order_by('vehicle_reg_no')
	serializer_class = CustomVehicleDetialSerializer
	filter_backends = [
			rest_framework.DjangoFilterBackend,
			filters.OrderingFilter,
			filters.SearchFilter
		]
	ordering_fields = (
			'vehicle_reg_no',
			'id',
			'date_added'
		)
	filter_fields = ('hire_status', 'make', 'model')
	search_fields = (
			'vehicle_reg_no',
			'supplier_id__first_name',
			'manufacturer_id__company'
		)

Usage in React JS/Next JS

npm install

npm i dynamic-muidatatable

Following is a sample implementation code.

import DynamicMUITable from "./DynamicMUITable"

const VehicleProfileCard = (value, tableMeta, updateValue) => {
	return (
		<ProfileCard reg_number={value.vehicle_reg_no} vehicle_id={value.id} />
	);
};

const ActionButtons = (value, tableMeta, updateValue) => {
	return (
		<>
            <ServiceDialog rowId={value} method="put" />
            <DeleteServiceDialog rowId={value} />
		</>
	);
};

const columnsCustom = [
	{
        name: "vehicle",
        label: "Reg Number",
        vehicle: true,
        sort: true,
        comp: VehicleProfileCard,
        display: true,
        filter: true,
        filterOptions: [],
        filterType: "dropdown",
        value: "reg_number",
	},
	new: [
            {
            	name: "id",
                label: "Label",
                comp: ActionButtons,
            }
	]
 ]

export default function DataTable() {
	return (
		<DynamicMUITable
		title="Table Title"
		urlLink="vehicle_accessories/service/list"
		columnsCustom={columnsCustom}
		/>
	)
}

API

<DynamicMUITable />

The component accepts the following props. | Name | Type | Description | | ------------------- | ----- | -------------------------------------------------------------------------------------------------------- | | title | array | Title used to caption table | | columnsCustom | array | Columns used to describe table. Must be either an array of simple strings or objects describing a column | | urlLink | array | API link to make a call to get data from the server |

Customize columnsCustom

On each column object, you have the ability to customize columns to your liking. | Name | Type | Default | Description | | ------------------- | ----------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | string | | Name of column (This field is required) | | label | string | | Column Header Name override | | vehicle | boolean | false | Incase, its main vehicle column | | sort | boolean | false | Enable/disable sorting on column. | | comp | function | | Custom function you want to show. function(value, tableMeta, updateValue) { return (<Component />)} | | value | array | | In case column is an object. This value defines to show specific index of the object. For e.g. vehicle: {id: 1, reg_number: "ABC-123"}. If you want to print reg_number, than {name: "vehicle", value: "reg_number"}. | | display | boolean or string | true | Display column in table. Possible values:true: Column is visible and toggleable via the View Columns popover in the Toolbar.false: Column is not visible but can be made visible via the View Columns popover in the Toolbar.excluded: Column is not visible and not toggleable via the View Columns popover in the Toolbar.See also: viewColumns and filter options. | | filter | boolean | false | Display column in filter list. | | filterOptions | object | | These options affect the filter display and functionality from the filter dialog. To modify the filter chips that display after selecting filters, see customFilterListOptionsThis option is an object of several options for customizing the filter display and how filtering works.names: custom names for the filter fields Examplelogic: custom filter logic Exampledisplay(filterList, onChange(filterList, index, column), index, column, filterData): Custom rendering inside the filter dialog Example. filterList must be of the same type in the main column options, that is an array of arrays, where each array corresponds to the filter list for a given column.renderValue: A function to customize filter choices Example. Example use case: changing empty strings to "(empty)" in a dropdown.fullWidth (boolean): Will force a filter option to take up the grid's full width. | | filterType | string | 'dropdown' | Choice of filtering view. Takes priority over global filterType option.enum('checkbox', 'dropdown', 'multiselect', 'textField', 'custom') Use 'custom' if you are supplying your own rendering via filterOptions. |

Cutom Columns

Insert new key in object as shown in example above.

| Name | Type | Description | | ----------- | -------- | ----------------------------------------------------------------------------------------------------- | | name | string | Name of column (This field is required) | | label | string | Column Header Name override | | comp | function | Custom function you want to show. function(value, tableMeta, updateValue) { return (<Component />)} |

Developed and Compiled: Hamza Fayyaz (Hayan Systems)