Comments (51)
sorry guys, as I mention on README, I already decide to create react-bootstrap-table2
, I trust it will be better than react-bootstrap-table
. A good news is I'll support the nested data in react-bootstrap-table2
start from v0.0.1
, bad news is I will not support the nested data in react-bootstrap-table
.
Feel free to let me know your idea and any idea/issues is welcome on react-bootstrap-table2
Sorry for inconvenience.
from react-bootstrap-table.
I'm using lodash's _.get
lib to achieve this.
import _ from 'lodash'
const renderCustom = (cell, row, extra) => {
const value = _.get(row, extra.path)
return <div>{value}</div>
}
const columns = [
{path: 'Person.firstname', title: 'Firstname'},
{path: 'Person.lastname', title: 'Lastname'},
{path: 'this.is.a.long.path.of.an.object', title: 'Long Path'},
]
const tableColumn = _.map(columns, (column) => (
<TableHeaderColumn
dataField={column.path}
dataFormat={renderCustom}
formatExtraData={column}
>{column.title}</TableHeaderColumn>
))
from react-bootstrap-table.
Working example with the required field is the key. Thanks to ferrwanz and nivek91.
import _ from 'lodash';
const renderCustom = (cell, row, extra) => {
const value = _.get(row, extra.path);
return <div>{value}</div>;
};
const columns = [
{ path: "id", title: "ID", isKey:true },
{ path: "animal.cat", title: "Cat" },
];
const tableColumn = _.map(columns, column => (
<TableHeaderColumn
dataField={column.path}
dataFormat={renderCustom}
formatExtraData={column}
isKey={column.isKey}
key={column.path}
>{column.title}</TableHeaderColumn>
));
Then you need to add to the method render, next code:
render() {
return(
<BootstrapTable data={ transactionData }>
{tableColumn}
</BootstrapTable>
);
}
from react-bootstrap-table.
I solved the issue without modification of the project 👍
<TableHeaderColumn dataField='Contact' dataFormat={ this.contactFormatter } >Contact</TableHeaderColumn>
and the function :
contactFormatter(cell, row){ return
${cell.first} ${cell.last}; }
from react-bootstrap-table.
building on @PraxentSupport's response. I'm using:
function objectFormat(data, cell) { if(data.constructor===Array){ if(data[0]=='last'){ return <p>${cell[data.length-1][data[1]]}</p> } return <p>${cell[data[0]][data[1]]}</p> } return <p>${cell[data]}</p>; }
dataFormat={ objectFormat.bind(this, [0,'address'])}
or
dataFormat={ objectFormat.bind(this, 'number')}
Note: need to ad ` around return values.
from react-bootstrap-table.
You can use formatExtraData
to hack
const column_meta = [
{columnName: 'user_detail.phone_number', displayName: 'User Phone'},
];
function extraFormatter(cell, row, extra) {
return eval(`row.${extra}`);
}
let columns = column_meta.map(i => {
return <TableHeaderColumn dataField={i.columnName} dataFormat={extraFormatter} formatExtraData={i.columnName}>
{i.displayName}</TableHeaderColumn>
});
then add colunms to BootstrapTable
.
from react-bootstrap-table.
And this is quite common case if you are using graphql.However, you can easily hack it even without eval, google js flattern object
you will get the answer.
from react-bootstrap-table.
I was just about to add to this... Why can't we simply make a PR that uses both the lodash _.get
:
https://lodash.com/docs/4.17.4#get
and _.set
:
https://lodash.com/docs/4.17.4#set
When retrieving and setting values?
from react-bootstrap-table.
@ferrwanz the key is missings in your code:
import _ from "lodash";
const renderCustom = (cell, row, extra) => {
const value = _.get(row, extra.path);
return
};
const columns = [
{ path: "CPA", title: "cpa", isKey: true },
{ path: "entreCalles.calleA", title: "entreCa" }
];
const tableColumn = _.map(columns, column => (
<TableHeaderColumn
dataField={column.path}
dataFormat={renderCustom}
formatExtraData={column}
isKey={column.isKey}
key={column.path}
{column.title}
from react-bootstrap-table.
To people finding this thread: Using lodash works well with displaying data but the data presented will not be searchable or sortable.
import _ from 'lodash'
const renderCustom = (cell, row, extra) => {
const value = _.get(row, extra.path)
return <div>{value}</div>
}
const filterValue = (cell, row) => {
//Cells that are subobjects won't hit this metod
debugger;
}
const columns = [
{path: 'Person.firstname', title: 'Firstname'},
{path: 'Person.lastname', title: 'Lastname'},
{path: 'this.is.a.long.path.of.an.object', title: 'Long Path'},
]
const tableColumn = _.map(columns, (column) => (
<TableHeaderColumn
dataField={column.path}
dataFormat={renderCustom}
formatExtraData={column}
filterValue={filterValue}
>{column.title}</TableHeaderColumn>
))
from react-bootstrap-table.
using dataFormat to rewrite this cell .
from react-bootstrap-table.
I did have a look at the code and this seems complicated to implement the way it is made. I doubt this feature will be added in the futur.
from react-bootstrap-table.
Hi @kopax, the nested object does not supported on newest version in this component, sorry for that. But I can add it in the future, but this is not in my plan, so I need more plan or thinking on this feature. :)
from react-bootstrap-table.
This feature is definitely welcomed. the fact that it does not support nested objects make it feel rather rigid in design. I hope to see this implemented soon =)
from react-bootstrap-table.
Ok, all I can say is thanks for sharing the code. Wait & see
from react-bootstrap-table.
Small workaround in the meantime is using the dataFormat.
Something like this works fine
function nameFormatter(data, cell) {
return `<p>${cell[data]}</p>`;
}
<TableHeaderColumn width='150' dataField='<nested_object>'
dataFormat={ nameFormatter.bind(this, <property_name>) }>Label</TableHeaderColumn>
from react-bootstrap-table.
I have made a little modification in TableBody.js
I don't know if this is enough for the rest of the feature provided by your lib, could you check a quick look ?
/blob/master/lib/TableBody.js line 101 replaced by :
var fieldValue = null;
if( column.name.indexOf('.') != -1 ){
var depth = column.name.split('.');
while(depth.length > 0){
fieldValue = fieldValue ? fieldValue[depth.shift()] : data[depth.shift()]
}
}
else{
fieldValue = data[column.name];
}
What do you think ?
I think you should also handle errors.
Edit: I have just tried with filter field, doesn't work (input placeholder is "Person.firstname")
from react-bootstrap-table.
Hi @kopax , it's a way to implement this feature and I think it will be OK. but there are a lots of feature in this component, include cell edit, filter ..etc. so I need to consider these part for design this feature, so it will take some time. Anyway, if you just want to "display" the nested data on component, I think your solution is ok :)
from react-bootstrap-table.
Hi @AllenFang , I am really trying hard to implement subobject management but the problem is that some comments are missing in your code.
Could you provide me further runtime details ?
My idea would be to add a dataPath="Person"
to TableHeaderColumn props
from react-bootstrap-table.
Hi @kopax , did you folk my project? I cant find your repository. I thinks I can spend a little time to watch out your folk and help you debug :)
from react-bootstrap-table.
I didn't for some (stupid) reasons :
I have two table Person and User
User doesn't have a primaryKey, the indexKey in User is person_id
The current add/edit feature add new User instance to dataSet with wrong nested Object (created key is "Person.firstname"
, insteand of "Person": { "firstname": ... }
I think I can't use this feature so I will need to do a bunch of modification just for my needs
from react-bootstrap-table.
Hi @kopax, you mean you want the add/edit feature work with nested object? If yes, I thinks it's a very very hard work. And you really cant solve the problem on your side, I can help you, but you need give me your folk first
from react-bootstrap-table.
@AllenFang sorry for not replying. I really liked your table unfortunately I wasn't able to implement anything in your code.
I would also love to reuse react-bootstrap-table in the futur so +1 for adding the feature
from react-bootstrap-table.
that's ok, I know this feature is very important, but I'm busy and there are lot of things to do, so I prefer to fix bug first. If I've free time, I'll come back and support this features. Anyway, PR is welcome :)
Thanks
from react-bootstrap-table.
+1
Will try and have a look at this too!
from react-bootstrap-table.
+1
from react-bootstrap-table.
+1
from react-bootstrap-table.
+1
from react-bootstrap-table.
+1
from react-bootstrap-table.
+1
from react-bootstrap-table.
@kopax, yes, it's little hard to implement.. I only have a way, is create a preparer and flat the nested object according user's defined and take this flatted object into table. I prefer to tackle v3.0.0
and go back to check my idea whether is work or not.
Sorry, make this issue pending...
from react-bootstrap-table.
Really need this feature too..
from react-bootstrap-table.
👍 Is there any fork of this project with this feature?
from react-bootstrap-table.
from react-bootstrap-table.
+1
from react-bootstrap-table.
This feature is really handy, please consider add this, thanks.
from react-bootstrap-table.
@gengjiawen, I will. Sorry for making this feature delay
from react-bootstrap-table.
+1
Working around it is fairly simple, but it shouldn't need a workaround at all.
from react-bootstrap-table.
+1 still no fix for this?
from react-bootstrap-table.
hey @nivek91, any thoughts on sorting this nested field?
from react-bootstrap-table.
which field @aaronhayes ?
from react-bootstrap-table.
@logolevel does all the features works ?
from react-bootstrap-table.
kopax, yes.
from react-bootstrap-table.
@logolevel thanks so much for this example.
I am trying to aggregate data within one column like animal.firstname + animal.lastname into a path (yes I named my cat with a full name ;)).
Does any one have a solution for that?
from react-bootstrap-table.
@StohlmanMatteo
works fine for me, thanks. just a quick note for all the other coming from google. just hsow how to use `` :-)
from react-bootstrap-table.
Building off the above: (This is using lodash but can work out how to use if dont want to use lodash/underscore)
First create a method in your react component like this replacing 'datapropertywithnested.nestedpropertyname' this your specifics:
depthFormatter(cell, row)
{
console.log("contactFormatter")
console.log(row)
console.log(cell)
let val = window._.get(row,'datapropertywithnested.nestedpropertyname');
return <div>{val ? val : 'none found'}</div>;
}
Then in your table:
<TableHeaderColumn dataField='anything' dataFormat={this.depthFormatter}> Custom </TableHeaderColumn>
from react-bootstrap-table.
However the above solution doesn't support filtering
As such I found the easiest solution is to modily your data before it enters the table to flatten it, such as through:
let data = tableData;
data = data.map((item,index) => {
if(_.has(item,'contact_company.name')) {
item.contact_company_name = item.contact_company.name;
}
return item;
});
Table as regular:
<BootstrapTable data={data}>
<TableHeaderColumn filter={{ type: 'TextFilter', delay: 100 }} dataSort={true} dataField='contact_company_name'>
Company Contact Name
</TableHeaderColumn>
</BootstrapTable>
from react-bootstrap-table.
Any updates?
from react-bootstrap-table.
@Ogglas any idea about sorting the field? or any approach to dataSort and also dataFormat with formatExtraData?
Thanks.
from react-bootstrap-table.
To go furthher into nested fields, i'm passing string and then returning the key/value pair.
const nestedFields = (data, row, field) => {
let nested_field = field.split(',');
return data[nested_field[0]][nested_field[1]];
}
<TableHeaderColumn row='1' dataField="torque_sensor" formatExtraData="top_hits,process" dataFormat={nestedFields} dataSort>Process</TableHeaderColumn>
from react-bootstrap-table.
Or the simplest way:
tableDataFormat(cell, index){
return (
<React.Fragment>
<span className="d-block">{index.name}</span>
<span className="d-block">{index.location}</span>
</React.Fragment>)
}
<TableHeaderColumn dataSort={ true } dataFormat={this.tableDataFormat}>Name </TableHeaderColumn>
you need also dataField
only if you are using isKey={ true }
on element
from react-bootstrap-table.
Related Issues (20)
- Read only on editable table for a field, but insert it in insertmodal HOT 1
- Sort icon not visible when text overflows in th
- Select All checkbox customization (Display any other icon instead of checkbox) HOT 2
- CellEdit is not working in firefox.
- Not showing Table border Tried Everything of Scripts importing CSS of bootstrap but still
- Warning: Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code.
- Select All doesn't persist across pages. HOT 1
- Not compatible with React 17+ HOT 6
- How to hide/show checkbox on particular rows in react bootstrap table next
- React Hooks, state is reseting to initial state when called onChange is called inside Formatter
- Expanding one row updating the value of all the expanded rows with the latest value
- How to get value of column selectFilter with deprecated react-boot-strap-table
- React Bootstrap Table - Iterate over an array of Objects for Datafield
- BootstrapTable is not reloading data when row checkbox checked or unchecked in ReactJS
- Error when search on page 2/3/4/5 etc
- Can't run the examples using gulp
- How can I delete/disable the "Expand All - Collapse All" button in the table header?
- Dynamic TableHeaderColumns with search and exportToCSV props doesn't work in BootstrapTable
- How can i use navigate pages using row ?
- React-data-table Component header alone is overlapping when the model/Pop us is enabled, HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-bootstrap-table.