mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
204 lines
24 KiB
HTML
204 lines
24 KiB
HTML
<html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Cell Edit · react-bootstrap-table2</title><meta name="viewport" content="width=device-width"/><meta name="generator" content="Docusaurus"/><meta property="og:title" content="Cell Edit · react-bootstrap-table2"/><meta property="og:type" content="website"/><meta property="og:url" content="https://react-bootstrap-table.github.io/react-bootstrap-table2/index.html"/><meta property="og:description" content="`react-bootstrap-table2` separate the cell edit code base to [`react-bootstrap-table2-editor`](https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/develop/packages/react-bootstrap-table2-editor), so there's a little bit different when you use cell edit than `react-bootstrap-table`. In the following, we are going to show you how to enable the cell edit"/><link rel="shortcut icon" href="/react-bootstrap-table2/undefined"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><link rel="alternate" type="application/atom+xml" href="https://react-bootstrap-table.github.io/blog/atom.xml" title="react-bootstrap-table2 Blog ATOM Feed"/><link rel="alternate" type="application/rss+xml" href="https://react-bootstrap-table.github.io/blog/feed.xml" title="react-bootstrap-table2 Blog RSS Feed"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><link rel="stylesheet" href="/react-bootstrap-table2/css/main.css"/></head><body class="sideNavVisible"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/react-bootstrap-table2/"><h2 class="headerTitle">react-bootstrap-table2</h2></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li><a href="/react-bootstrap-table2/docs/about.html" target="_self">Docs</a></li><li><a href="/react-bootstrap-table2/docs/table-props.html" target="_self">API</a></li><li><a href="/react-bootstrap-table2/en/help.html" target="_self">Help</a></li><li><a href="/react-bootstrap-table2/blog" target="_self">Blog</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container docsNavContainer" id="docsNav"><nav class="toc"><div class="toggleNav"><section class="navWrapper wrapper"><div class="navBreadcrumb wrapper"><div class="navToggle" id="navToggler"><i></i></div><h2><i>›</i><span>Basic Usage</span></h2></div><div class="navGroups"><div class="navGroup navGroupActive"><h3>Getting Started</h3><ul><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/about.html">About</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/getting-started.html">Getting Started</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/bootstrap4.html">Bootstrap 4</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/migration.html">Migration</a></li></ul></div><div class="navGroup navGroupActive"><h3>Basic Usage</h3><ul><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-row.html">Work on Row</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-column.html">Work on Column</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-sort.html">Table Sort</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-row-select.html">Row Selection</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-filter.html">Column Filter</a></li><li class="navListItem navListItemActive"><a class="navItem navItemActive" href="/react-bootstrap-table2/docs/basic-celledit.html">Cell Edit</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-pagination.html">Pagination</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-row-expand.html">Expandable Row</a></li></ul></div><div class="navGroup navGroupActive"><h3>Remote Table</h3><ul><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-remote.html">Work on Remote</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/overlay.html">Overlay</a></li></ul></div><div class="navGroup navGroupActive"><h3>Table Toolkits</h3><ul><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/toolkits-getting-started.html">Getting Started</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-search.html">Table Search</a></li><li class="navListItem"><a class="navItem" href="/react-bootstrap-table2/docs/basic-export-csv.html">Export to CSV</a></li></ul></div></div></section></div><script>
|
||
var toggler = document.getElementById('navToggler');
|
||
var nav = document.getElementById('docsNav');
|
||
toggler.onclick = function() {
|
||
nav.classList.toggle('docsSliderActive');
|
||
};
|
||
</script></nav></div><div class="container mainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><h1>Cell Edit</h1></header><article><div><span><p><code>react-bootstrap-table2</code> separate the cell edit code base to <a href="https://github.com/react-bootstrap-table/react-bootstrap-table2/tree/develop/packages/react-bootstrap-table2-editor"><code>react-bootstrap-table2-editor</code></a>, so there's a little bit different when you use cell edit than <code>react-bootstrap-table</code>. In the following, we are going to show you how to enable the cell edit</p>
|
||
<p><strong><a href="../storybook/index.html?selectedKind=Cell%20Editing">Live Demo For Cell Edit</a></strong> <br>
|
||
<strong><a href="./cell-edit-props.html">API & Props Definition</a></strong></p>
|
||
<hr>
|
||
<h2><a class="anchor" aria-hidden="true" name="install"></a><a href="#install" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Install</h2>
|
||
<pre><code class="hljs css sh">$ npm install react-bootstrap-table2-editor --save
|
||
</code></pre>
|
||
<h2><a class="anchor" aria-hidden="true" name="how"></a><a href="#how" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>How</h2>
|
||
<p>We have <a href="./cell-edit-props.html#celleditmode-string">two ways</a> to trigger a editable cell as editing cell:</p>
|
||
<ul>
|
||
<li>click</li>
|
||
<li>dbclick</li>
|
||
</ul>
|
||
<p>That's look into how we enable the cell edit on tabe:</p>
|
||
<pre><code class="hljs css js"><span class="hljs-keyword">import</span> cellEditFactory <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap-table2-editor'</span>;
|
||
|
||
<span class="hljs-comment">// omit</span>
|
||
|
||
<BootstrapTable
|
||
keyField=<span class="hljs-string">"id"</span>
|
||
data={ products }
|
||
columns={ columns }
|
||
cellEdit={ cellEditFactory({ <span class="hljs-attr">mode</span>: <span class="hljs-string">'click'</span> }) }
|
||
/>
|
||
</code></pre>
|
||
<p>How user save their new editings? We offer two ways:</p>
|
||
<ul>
|
||
<li>Press ENTER(<strong>default</strong>)</li>
|
||
<li>Blur from current editing cell(Need to enable the <a href="./cell-edit-props.html#celleditblurtosave-bool">cellEdit.blurToSave</a>)</li>
|
||
</ul>
|
||
<h2><a class="anchor" aria-hidden="true" name="editable-cell"></a><a href="#editable-cell" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Editable Cell</h2>
|
||
<p><code>react-bootstrap-table2</code> support you to configure the cell editable on three level:</p>
|
||
<ul>
|
||
<li>Row Level (<a href="./cell-edit-props.html#celleditnoneditablerows-function">cellEdit.nonEditableRows</a>)</li>
|
||
<li>Column Level (Configure <a href="./column-props.html#columneditable-bool-function">column.editable</a> as bool value)</li>
|
||
<li>Cell Level (Configure <a href="./column-props.html#columneditable-bool-function">column.editable</a> as a callback function)</li>
|
||
</ul>
|
||
<h2><a class="anchor" aria-hidden="true" name="validation"></a><a href="#validation" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Validation</h2>
|
||
<p><a href="./column-props.html#columnvalidator-function"><code>column.validator</code></a> will help you to work on it!</p>
|
||
<h2><a class="anchor" aria-hidden="true" name="customize-style-class"></a><a href="#customize-style-class" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Customize Style/Class</h2>
|
||
<ul>
|
||
<li>Customize the editing cell style via <a href="./column-props.html#columneditcellstyle-object-function">column.editCellStyle</a></li>
|
||
<li>Customize the editing cell classname via <a href="./column-props.html#columneditcellclasses-string-function">column.editCellClasses</a></li>
|
||
<li>Customize the editor style via <a href="./column-props.html#columneditorstyle-object-function">column.editorStyle</a></li>
|
||
<li>Customize the editor classname via <a href="./column-props.html#columneditorclasses-string-function">column.editoClasses</a></li>
|
||
</ul>
|
||
<h2><a class="anchor" aria-hidden="true" name="rich-editors"></a><a href="#rich-editors" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Rich Editors</h2>
|
||
<p><code>react-bootstrap-table2</code> have following predefined editor:</p>
|
||
<ul>
|
||
<li>Text(Default)</li>
|
||
<li>Dropdown</li>
|
||
<li>Date</li>
|
||
<li>Textarea</li>
|
||
<li>Checkbox</li>
|
||
</ul>
|
||
<p>In a nutshell, you just only give a <a href="https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/column-props.html#columneditor-object">column.editor</a> and define the <code>type</code>:</p>
|
||
<pre><code class="hljs css js"><span class="hljs-keyword">import</span> { Type } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap-table2-editor'</span>;
|
||
<span class="hljs-keyword">const</span> columns = [
|
||
..., {
|
||
<span class="hljs-attr">dataField</span>: <span class="hljs-string">'done'</span>,
|
||
<span class="hljs-attr">text</span>: <span class="hljs-string">'Done'</span>,
|
||
<span class="hljs-attr">editor</span>: {
|
||
<span class="hljs-attr">type</span>: Type.SELECT | Type.TEXTAREA | Type.CHECKBOX | Type.DATE,
|
||
... <span class="hljs-comment">// The rest properties will be rendered into the editor's DOM element</span>
|
||
}
|
||
}
|
||
]
|
||
</code></pre>
|
||
<p>In the following, we go though all the predefined editors:</p>
|
||
<h3><a class="anchor" aria-hidden="true" name="dropdown-editor"></a><a href="#dropdown-editor" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Dropdown Editor</h3>
|
||
<p>Dropdown editor give a select menu to choose a data from a list, the <code>editor.options</code> is required property for dropdown editor.</p>
|
||
<pre><code class="hljs css js"><span class="hljs-keyword">import</span> { Type } <span class="hljs-keyword">from</span> <span class="hljs-string">'react-bootstrap-table2-editor'</span>;
|
||
<span class="hljs-keyword">const</span> columns = [
|
||
..., {
|
||
<span class="hljs-attr">dataField</span>: <span class="hljs-string">'type'</span>,
|
||
<span class="hljs-attr">text</span>: <span class="hljs-string">'Job Type'</span>,
|
||
<span class="hljs-attr">editor</span>: {
|
||
<span class="hljs-attr">type</span>: Type.SELECT,
|
||
<span class="hljs-attr">options</span>: [{
|
||
<span class="hljs-attr">value</span>: <span class="hljs-string">'A'</span>,
|
||
<span class="hljs-attr">label</span>: <span class="hljs-string">'A'</span>
|
||
}, {
|
||
<span class="hljs-attr">value</span>: <span class="hljs-string">'B'</span>,
|
||
<span class="hljs-attr">label</span>: <span class="hljs-string">'B'</span>
|
||
}, {
|
||
<span class="hljs-attr">value</span>: <span class="hljs-string">'C'</span>,
|
||
<span class="hljs-attr">label</span>: <span class="hljs-string">'C'</span>
|
||
}, {
|
||
<span class="hljs-attr">value</span>: <span class="hljs-string">'D'</span>,
|
||
<span class="hljs-attr">label</span>: <span class="hljs-string">'D'</span>
|
||
}, {
|
||
<span class="hljs-attr">value</span>: <span class="hljs-string">'E'</span>,
|
||
<span class="hljs-attr">label</span>: <span class="hljs-string">'E'</span>
|
||
}]
|
||
}
|
||
}];
|
||
</code></pre>
|
||
<h3><a class="anchor" aria-hidden="true" name="date-editor"></a><a href="#date-editor" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Date Editor</h3>
|
||
<p>Date editor is use <code><input type="date"></code>, the configuration is very simple:</p>
|
||
<pre><code class="hljs css js"><span class="hljs-keyword">const</span> columns = [
|
||
..., {
|
||
<span class="hljs-attr">dataField</span>: <span class="hljs-string">'inStockDate'</span>,
|
||
<span class="hljs-attr">text</span>: <span class="hljs-string">'Stock Date'</span>,
|
||
<span class="hljs-attr">formatter</span>: <span class="hljs-function">(<span class="hljs-params">cell</span>) =></span> {
|
||
<span class="hljs-keyword">let</span> dateObj = cell;
|
||
<span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> cell !== <span class="hljs-string">'object'</span>) {
|
||
dateObj = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(cell);
|
||
}
|
||
<span class="hljs-keyword">return</span> <span class="hljs-string">`<span class="hljs-subst">${(<span class="hljs-string">'0'</span> + dateObj.getDate()).slice(<span class="hljs-number">-2</span>)}</span>/<span class="hljs-subst">${(<span class="hljs-string">'0'</span> + (dateObj.getMonth() + <span class="hljs-number">1</span>)).slice(<span class="hljs-number">-2</span>)}</span>/<span class="hljs-subst">${dateObj.getFullYear()}</span>`</span>;
|
||
},
|
||
<span class="hljs-attr">editor</span>: {
|
||
<span class="hljs-attr">type</span>: Type.DATE
|
||
}
|
||
}];
|
||
</code></pre>
|
||
<h3><a class="anchor" aria-hidden="true" name="textarea-editor"></a><a href="#textarea-editor" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Textarea Editor</h3>
|
||
<p>Textarea editor is use <code><input type="textarea"></code>, user can press <code>ENTER</code> to change line and in the <code>react-bootstrap-table2</code>, user allow to save result via press <code>SHIFT</code> + <code>ENTER</code>.</p>
|
||
<pre><code class="hljs css js"><span class="hljs-keyword">const</span> columns = [
|
||
..., {
|
||
<span class="hljs-attr">dataField</span>: <span class="hljs-string">'comment'</span>,
|
||
<span class="hljs-attr">text</span>: <span class="hljs-string">'Product Comments'</span>,
|
||
<span class="hljs-attr">editor</span>: {
|
||
<span class="hljs-attr">type</span>: Type.TEXTAREA
|
||
}
|
||
}];
|
||
</code></pre>
|
||
<h3><a class="anchor" aria-hidden="true" name="checkbox-editor"></a><a href="#checkbox-editor" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Checkbox Editor</h3>
|
||
<p>Checkbox editor allow you to have a pair value choice, the <code>editor.value</code> is required value to represent the actual value for check and uncheck.</p>
|
||
<pre><code class="hljs css js"><span class="hljs-keyword">const</span> columns = [
|
||
..., {
|
||
<span class="hljs-attr">dataField</span>: <span class="hljs-string">'comment'</span>,
|
||
<span class="hljs-attr">text</span>: <span class="hljs-string">'Product Comments'</span>,
|
||
<span class="hljs-attr">editor</span>: {
|
||
<span class="hljs-attr">type</span>: Type.CHECKBOX,
|
||
<span class="hljs-attr">value</span>: <span class="hljs-string">'Y:N'</span>
|
||
}
|
||
}];
|
||
</code></pre>
|
||
<h2><a class="anchor" aria-hidden="true" name="customize-editor"></a><a href="#customize-editor" aria-hidden="true" class="hash-link" ><svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Customize Editor</h2>
|
||
<p>If you feel above predefined editors are not satisfied to your requirement, you can certainly custom the editor via <a href="https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/column-props.html#columneditorrenderer-function">column.editorRenderer</a>. It accept a function and pass following arguments when function called:</p>
|
||
<ul>
|
||
<li><code>editorProps</code>: Some useful attributes you can use on DOM editor, like class, style etc.</li>
|
||
<li><code>value</code>: Current cell value</li>
|
||
<li><code>row</code>: Current row data</li>
|
||
<li><code>column</code>: Current column definition</li>
|
||
<li><code>rowIndex</code>: Current row index</li>
|
||
<li><code>columnIndex</code>: Current column index</li>
|
||
</ul>
|
||
<blockquote>
|
||
<p>Note when implement a custom React editor component, this component should have a <strong>getValue</strong> function which return current value on editor</p>
|
||
</blockquote>
|
||
<blockquote>
|
||
<p>Note when you want to save value, you can call <strong>editorProps.onUpdate</strong> function</p>
|
||
</blockquote>
|
||
<p>Following is a short example:</p>
|
||
<pre><code class="hljs css js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">QualityRanger</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
|
||
<span class="hljs-keyword">static</span> propTypes = {
|
||
<span class="hljs-attr">value</span>: PropTypes.number,
|
||
<span class="hljs-attr">onUpdate</span>: PropTypes.func.isRequired
|
||
}
|
||
<span class="hljs-keyword">static</span> defaultProps = {
|
||
<span class="hljs-attr">value</span>: <span class="hljs-number">0</span>
|
||
}
|
||
getValue() {
|
||
<span class="hljs-keyword">return</span> <span class="hljs-built_in">parseInt</span>(<span class="hljs-keyword">this</span>.range.value, <span class="hljs-number">10</span>);
|
||
}
|
||
render() {
|
||
<span class="hljs-keyword">const</span> { value, onUpdate, ...rest } = <span class="hljs-keyword">this</span>.props;
|
||
<span class="hljs-keyword">return</span> [
|
||
<input
|
||
{ ...rest }
|
||
key="range"
|
||
ref={ node => this.range = node }
|
||
type="range"
|
||
min="0"
|
||
max="100"
|
||
/>,
|
||
<button
|
||
key="submit"
|
||
className="btn btn-default"
|
||
onClick={ () => onUpdate(this.getValue()) }
|
||
>
|
||
done
|
||
</button>
|
||
];
|
||
}
|
||
}
|
||
|
||
const columns = [
|
||
..., {
|
||
dataField: 'quality',
|
||
text: 'Product Quality',
|
||
editorRenderer: (editorProps, value, row, column, rowIndex, columnIndex) => (
|
||
<QualityRanger { ...editorProps } value={ value } />
|
||
)
|
||
}];
|
||
</code></pre>
|
||
</span></div></article></div><div class="docs-prevnext"><a class="docs-prev button" href="basic-filter.html">← Column Filter</a><a class="docs-next button" href="basic-pagination.html">Pagination →</a></div></div></div></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/react-bootstrap-table2/" class="nav-home"></a><div><h5>Docs</h5><a href="/react-bootstrap-table2/docs/en/getting-started.html">Getting Started</a><a href="/react-bootstrap-table2/docs/en/table-props.html">API References</a></div><div><h5>Community</h5><a href="https://stackoverflow.com/questions/tagged/react-bootstrap-table" target="_blank">Stack Overflow</a><a href="https://discordapp.com/">Project Chat</a><a href="https://twitter.com/" target="_blank">Twitter</a></div><div><h5>More</h5><a href="/react-bootstrap-table2/blog/index.html">Blog</a><a href="https://github.com/react-bootstrap-table/react-bootstrap-table2">GitHub</a><a class="github-button" href="https://github.com/react-bootstrap-table/react-bootstrap-table2" data-icon="octicon-star" data-count-href="/facebook/docusaurus/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star this project on GitHub">Star</a></div></section><section class="copyright">Copyright © 2018 react-bootstrap-table2.</section></footer></div></body></html> |