-
Notifications
You must be signed in to change notification settings - Fork 0
/
792a2f43.39b48e3c.js
1 lines (1 loc) · 8.23 KB
/
792a2f43.39b48e3c.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[38],{111:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return o})),n.d(t,"toc",(function(){return c})),n.d(t,"default",(function(){return u}));var r=n(3),a=(n(0),n(165)),l=(n(179),n(177));const i={id:"custom-filter",title:"Custom Column Filter",hide_title:!0},o={unversionedId:"filter/custom-filter",id:"filter/custom-filter",isDocsHomePage:!1,title:"Custom Column Filter",description:"Custom Column Filter",source:"@site/demos/filter/custom-filter.mdx",slug:"/filter/custom-filter",permalink:"/demos/filter/custom-filter",version:"current",sidebar:"sidebar",previous:{title:"Basic Filtering",permalink:"/demos/filter/basic"},next:{title:"Custom Filter Row",permalink:"/demos/filter/custom-filter-row"}},c=[{value:"Props",id:"props",children:[]},{value:"FilterComponent",id:"filtercomponent",children:[]},{value:"Usage",id:"usage",children:[]},{value:"Live Demo",id:"live-demo",children:[]}],m={toc:c};function u(e){let{components:t,...n}=e;return Object(a.b)("wrapper",Object(r.a)({},m,n,{components:t,mdxType:"MDXLayout"}),Object(a.b)("h1",{id:"custom-column-filter"},"Custom Column Filter"),Object(a.b)("h2",{id:"props"},"Props"),Object(a.b)("table",null,Object(a.b)("thead",{parentName:"table"},Object(a.b)("tr",{parentName:"thead"},Object(a.b)("th",{parentName:"tr",align:null},"Field"),Object(a.b)("th",{parentName:"tr",align:null},"Type"),Object(a.b)("th",{parentName:"tr",align:null},"Description"))),Object(a.b)("tbody",{parentName:"table"},Object(a.b)("tr",{parentName:"tbody"},Object(a.b)("td",{parentName:"tr",align:null},Object(a.b)("inlineCode",{parentName:"td"},"options.filtering")),Object(a.b)("td",{parentName:"tr",align:null},"boolean"),Object(a.b)("td",{parentName:"tr",align:null},"display filter row on table")),Object(a.b)("tr",{parentName:"tbody"},Object(a.b)("td",{parentName:"tr",align:null},Object(a.b)("inlineCode",{parentName:"td"},"columns.filterComponent")),Object(a.b)("td",{parentName:"tr",align:null},"React.Element"),Object(a.b)("td",{parentName:"tr",align:null},"custom component for filtering")))),Object(a.b)("h2",{id:"filtercomponent"},"FilterComponent"),Object(a.b)("p",null,"The filterComponent passes these props to hook it to the table internal filtering:"),Object(a.b)("table",null,Object(a.b)("thead",{parentName:"table"},Object(a.b)("tr",{parentName:"thead"},Object(a.b)("th",{parentName:"tr",align:null},"Field"),Object(a.b)("th",{parentName:"tr",align:null},"Type"),Object(a.b)("th",{parentName:"tr",align:null},"Description"))),Object(a.b)("tbody",{parentName:"table"},Object(a.b)("tr",{parentName:"tbody"},Object(a.b)("td",{parentName:"tr",align:null},Object(a.b)("inlineCode",{parentName:"td"},"columnDef")),Object(a.b)("td",{parentName:"tr",align:null},"Column"),Object(a.b)("td",{parentName:"tr",align:null},"the current column of the filter")),Object(a.b)("tr",{parentName:"tbody"},Object(a.b)("td",{parentName:"tr",align:null},Object(a.b)("inlineCode",{parentName:"td"},"onFilterChanged")),Object(a.b)("td",{parentName:"tr",align:null},"(columnId: string, value: any) => void;"),Object(a.b)("td",{parentName:"tr",align:null},"the callback for the onChange")))),Object(a.b)("h2",{id:"usage"},"Usage"),Object(a.b)("pre",null,Object(a.b)("code",{parentName:"pre",className:"language-jsx"},'import MaterialTable from "@material-table/core";\n\n<MaterialTable\n // ...\n options={{\n filtering: true,\n }}\n/>;\n')),Object(a.b)("h2",{id:"live-demo"},"Live Demo"),Object(a.b)(l.a,{mdxType:"InfoBannerAboutGlobalVarsInDemos"}),Object(a.b)("pre",null,Object(a.b)("code",{parentName:"pre",className:"language-jsx",metastring:"live",live:!0},'function CustomFilter() {\n return (\n <MaterialTable\n data={[\n {\n name: "Mehmet",\n surname: "Baran",\n birthYear: 1987,\n birthCity: 63,\n },\n {\n name: "Zerya Bet\xfcl",\n surname: "Baran",\n birthYear: 2017,\n birthCity: 34,\n },\n ]}\n columns={[\n {\n title: "Name",\n field: "name",\n filterComponent: ({ columnDef, onFilterChanged }) => (\n <input\n placeholder="custom"\n onChange={(e) => {\n // Calling the onFilterChanged with the current tableId and the new value\n onFilterChanged(columnDef.tableData.id, e.target.value);\n }}\n />\n ),\n },\n {\n title: "Surname",\n field: "surname",\n },\n {\n title: "Birth Year",\n field: "birthYear",\n type: "numeric",\n },\n {\n title: "Birth Place",\n field: "birthCity",\n lookup: {\n 34: "\u0130stanbul",\n 63: "\u015eanl\u0131urfa",\n },\n },\n ]}\n options={{\n filtering: true,\n }}\n />\n );\n}\n')))}u.isMDXComponent=!0},165:function(e,t,n){"use strict";n.d(t,"a",(function(){return b})),n.d(t,"b",(function(){return f}));var r=n(0),a=n.n(r);function l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){l(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},l=Object.keys(e);for(r=0;r<l.length;r++)n=l[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(r=0;r<l.length;r++)n=l[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var m=a.a.createContext({}),u=function(e){var t=a.a.useContext(m),n=t;return e&&(n="function"==typeof e?e(t):o(o({},t),e)),n},b=function(e){var t=u(e.components);return a.a.createElement(m.Provider,{value:t},e.children)},p="mdxType",s={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},d=a.a.forwardRef((function(e,t){var n=e.components,r=e.mdxType,l=e.originalType,i=e.parentName,m=c(e,["components","mdxType","originalType","parentName"]),b=u(n),p=r,d=b["".concat(i,".").concat(p)]||b[p]||s[p]||l;return n?a.a.createElement(d,o(o({ref:t},m),{},{components:n})):a.a.createElement(d,o({ref:t},m))}));function f(e,t){var n=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var l=n.length,i=new Array(l);i[0]=d;var o={};for(var c in t)hasOwnProperty.call(t,c)&&(o[c]=t[c]);o.originalType=e,o[p]="string"==typeof e?e:r,i[1]=o;for(var m=2;m<l;m++)i[m]=n[m];return a.a.createElement.apply(null,i)}return a.a.createElement.apply(null,n)}d.displayName="MDXCreateElement"},177:function(e,t,n){"use strict";n.d(t,"a",(function(){return c}));var r=n(0),a=n.n(r),l=(n(20),n(413)),i=n(244);const o=e=>{let{type:t,children:n}=e,r=t;return"tip"===t&&(r="success"),"note"===t&&(r="secondary"),a.a.createElement(l.a,{theme:Object(i.b)()},a.a.createElement("div",{className:`admonition admonition-${t} alert alert--${r}`},a.a.createElement("div",{className:"admonition-heading"},a.a.createElement("h5",null,a.a.createElement("span",{className:"admonition-icon"},a.a.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"16",viewBox:"0 0 14 16"},a.a.createElement("path",{fillRule:"evenodd",d:"M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"}))),t.toLowerCase())),a.a.createElement("div",{className:"admonition-content"},a.a.createElement("p",null,n))))},c=()=>a.a.createElement(o,{type:"note"},"See"," ",a.a.createElement("a",{href:"/demos/#demo-environment"},a.a.createElement("b",null,a.a.createElement("i",null,"here")))," ","for more on the ",a.a.createElement("code",null,"GLOBAL_VARS")," we use in our demos")}}]);