Custom Search Toolbar Not Rendering my Custom Element, Uses Default.
See original GitHub issueHello!
After trying many react datatables, I have decided that react-bootstrap-table is by far the best design, great work! I’m experiencing some difficulties however. I want to completely modify the table header so it renders a custom themed search bar and tool bar that matches my table styling. Here is a screenshot of the expected end result:
I’ve been able to theme the table just fine but the code I have written for the header toolbar doesn’t render but no exceptions are thrown by webpack or browser console so I’m not sure what I’m doing wrong or if this is perhaps a bug. Help is much appreciated!
My Table Search class which returns the custom toolbar HTML
class CyhyTableSearch extends React.Component {
getValue() {
return ReactDOM.findDOMNode(this).value;
}
setValue(value) {
ReactDOM.findDOMNode(this).value = value;
}
render() {
return (
<div className="flakes-search">
<input
ref="search-input"
className="flakes-search"
placeholder={ this.props.placeholder }
defaultValue={ this.props.defaultValue }
onKeyUp={ this.props.search } />
<div className="flakes-actions-bar">
<button
className="action button-gray smaller right"
defaultValue="Add Value" />
<button
className="action button-gray smaller right"
defaultValue="Export CSV" />
</div>
</div>
);
}
}
And my Table Class:
class CyhyTable extends React.Component {
csvFormatter(cell, row) {
return `${row.id}: ${cell} USD`;
}
render() {
const selectRowProp = {
mode: 'checkbox'
};
const options = {
clearSearch: false,
searchPanel: (props) => (<CyhyTableSearch { ...props }/>),
page: 1, // which page you want to show as default
sizePerPage: 25, // which size per page you want to locate as default
pageStartIndex: 0, // where to start counting the pages
paginationSize: 3, // the pagination bar size.
prePage: 'Prev', // Previous page button text
nextPage: 'Next', // Next page button text
firstPage: 'First', // First page button text
lastPage: 'Last', // Last page button text
sizePerPageList: [ {
text: '5', value: 5
}, {
text: '10', value: 10
}, {
text: '15', value: 15
}, {
text: '25', value: 25
}, {
text: '50', value: 50
}, {
text: '100', value: 100
}, {
text: 'All', value: cyhyData.length
} ],
};
return (
<BootstrapTable
data={ cyhyData }
options={ options }
selectRow={ selectRowProp }
exportCSV={ true }
pagination={ true }
tableHeaderClass='flakes-table'
tableBodyClass='flakes-table'
containerClass='flakes-table'
tableContainerClass='flakes-table'
headerContainerClass='flakes-table'
bodyContainerClass='flakes-table'
search >
<TableHeaderColumn dataField='Facility'>Facility</TableHeaderColumn>
<TableHeaderColumn dataField='Severity'>Severity</TableHeaderColumn>
<TableHeaderColumn dataField='DNS'>DNS</TableHeaderColumn>
<TableHeaderColumn isKey={true} dataField='IP'>IP</TableHeaderColumn>
<TableHeaderColumn dataField='Port'>Port</TableHeaderColumn>
<TableHeaderColumn dataField='vulnName'>Vulnerability</TableHeaderColumn>
</BootstrapTable>
);
}
}
And my app.js render method:
ReactDOM.render(
<CyhyTable />,
document.getElementById('table')
);
And this is the rendered result:
Everything is rendered default so it appears.
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (6 by maintainers)
Top GitHub Comments
Fantastic! Worked like a charm. Thank you for providing such great dev support!
My only request for 3.0 is show/hide columns. I’ve been working on my own solution based off #299 @lcb’s solution:
however, when using his code only the ID field has its state changed, and the checkbox’s remain stuck in a “checked” state and cannot be toggled. This issue is easily pointed towards
Object.assign(this.state.hiddenColumns, { id: !this.state.hiddenColumns.id })
So I cooked up my own solution implementing a nicely styled modal and some code which would probably be considered hacky but it works well! Any optimization tips perhaps? 😃
This table will show/hide any column from popup modal(styles included if needed and lazily added at top), and implements custom CSV export functionality which allows user to select rows to be exported.
Everything is working great! Still need to now integrate custom column selector into the toolbar and add sorting/pagination but that stuff should go quick now 😃
Thanks Again!
hi can u help me with the following error…while adding a new row the background in the popup is not getting changed…wt i need to do for this…i cnt find the css lso…
hre is d code…
import React from ‘react’; import { BootstrapTable, TableHeaderColumn, InsertButton, DeleteButton, SizePerPageDropDown } from ‘react-bootstrap-table’; import ‘./react-bootstrap-table.css’; const jobs = []; const jobTypes = [{ value: ‘A’, text: ‘TYPE_A’ }, { value: ‘B’, text: ‘TYPE_B’ }, { value: ‘C’, text: ‘TYPE_C’ }, { value: ‘D’, text: ‘TYPE_D’ }];
function addJobs(quantity) { const startId = jobs.length; //alert(jobs.length); for (let i = 0; i < quantity; i++) { //alert(jobs.length) const id = startId + i; jobs.push({ id: id, name: 'Item name ’ + id, type1: ‘A’, type2: ‘B’, active: i % 2 === 0 ? ‘Y’ : ‘N’, date: ‘200’ + i + ‘-12-28’ }); } }
addJobs(15);
const cellEditProp = { mode: ‘click’, blurToSave: true }; class ActiveFormatter extends React.Component { render() { return ( ); } }
export default class EditTypeTable extends React.Component {
constructor(props) { super(props); }
formatType(cell) { return
TYPE_${cell}
; }jobTypes(row) {
}
createCustomInsertButton = (onClick) => {
} createCustomDeleteButton = (onClick) => { return ( <button style={{ color: ‘red’ }} onClick={onClick}>Delete Row</button> ); } createCustomExportCSVButton = (onClick) => { return ( <button style={{ color: ‘blue’ }} onClick={onClick}>Export CSV</button> ); } createCustomClearButton = (onClick) => { return ( <button style={{ color: ‘green’ }} onClick={onClick}>Clear Search</button> ); }
render() { const options = { insertBtn: this.createCustomInsertButton,
};
}