Skip to content

Instantly share code, notes, and snippets.

@nidheeshdas
Created September 7, 2018 13:46
Show Gist options
  • Save nidheeshdas/ebdb07d147d7ff89e09bb44fe822ba31 to your computer and use it in GitHub Desktop.
Save nidheeshdas/ebdb07d147d7ff89e09bb44fe822ba31 to your computer and use it in GitHub Desktop.
DTS for mui-datatables: makeshift yet usable
declare module "mui-datatables" {
import { ReactNode } from "react";
export interface MUIDataTableColumn {
name: string
options?: MUIDataTableColumnOptions
}
export interface MUIDataTableColumnOptions {
display?: "true" | "false" | "excluded"
filter?: boolean
sort?: boolean
download?: boolean
customHeadRender?: (value, tableMeta, updateValue) => string
customBodyRender?: (value, tableMeta, updateValue) => string | ReactNode
}
export interface MUIDataTableOptions {
page?: number
count?: number
serverSide?: boolean
filterList?: any[]
rowsSelected?: any[]
filterType?: string
textLabels?: object
pagination?: boolean
selectableRows?: boolean
resizableColumns?: boolean
customToolbar?: () => ReactNode
customToolbarSelect?: () => ReactNode
customFooter?: () => ReactNode
caseSensitive?: boolean
responsive?: string
rowsPerPage?: number
rowsPerPageOptions?: number[]
rowHover?: boolean
sortFilterList?: boolean
sort?: boolean
filter?: boolean
search?: boolean
print?: boolean
download?: boolean
downloadOptions?: { filename: string, separator: string }
viewColumns?: boolean
onRowsSelect?: (currentRowsSelected: any[], rowsSelected: any[]) => void
onRowsDelete?: (rowsDeleted: any[]) => void
onRowClick?: (rowData: string[], rowMeta: { dataIndex: number, rowIndex: number }) => void
onCellClick?: (colIndex: number, rowIndex: number) => void
onChangePage?: (currentPage: number) => void
onChangeRowsPerPage?: (numberOfRows: number) => void
onSearchChange?: (searchText: string) => void
onFilterChange?: (changedColumn: string, filterList: any[]) => void
onColumnSortChange?: (changedColumn: string, direction: string) => void
onColumnViewChange?: (changedColumn: string, action: string) => void
onServerRequest?: (action: string, tableState: MuiDatatablesTableState) => void
}
export interface MuiDatatablesTableState {
page: number
rowsPerPage: number
filterList: any[]
}
export type MUIDataTableColumnDef = string | MUIDataTableColumn;
export interface MUIDataTableProps {
title: string
columns: MUIDataTableColumnDef[]
data: any[]
options?: MUIDataTableOptions
}
export const MUIDataTable: React.ComponentType<MUIDataTableProps>;
export default MUIDataTable;
}
@JReinhold
Copy link

great job, just what I was looking for, thanks!

@kaleshasheik
Copy link

I am getting below exception

warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Any idea ?

@favna
Copy link

favna commented Feb 3, 2019

This should be deprecated in favor of @types/mui-datatables. I took this gist as a basis and updated it to be proper for the latest published version of mui-datatables (2.0.0-beta-53 at time of writing) as well as DefinitetlyTyped standards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment