-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can i bind my own response data to table #11
Comments
@rohitsharmahub thanks for using this package you can pass the data to the table from your server response by ...
const url = 'https://example.test/api/users';
const columns = ['id', 'name', 'email', 'avatar', 'address', 'created_at', 'actions'];
const options = {
...
responseAdapter: function (resp_data) {
return {data: resp_data.data, total: resp_data.meta.total}
},
};
...
<ServerTable columns={columns} url={url} options={options}>
{
function (row, column) {
switch (column) {
case 'avatar':
return (<img src={row.avatar} className="table-image"/>);
case 'address':
return (
<ul>
<li>Street: {row.address.address1}</li>
<li>City: {row.address.city}</li>
<li>Country: {row.address.country}</li>
</ul>
);
case 'actions':
return (
<div style={{textAlign: 'center'}}>
<a className="btn btn-primary btn-xs table-actions-btn"
href={'users/' + row.id + '/edit'}>
<i className="fa fa-pencil-alt"/></a>
<a className="btn btn-danger btn-xs table-actions-btn">
<i className="fa fa-trash"/></a>
</div>
);
default: // Don't forget this
return (row[column]);
}
}
}
</ServerTable> you can view a full example here Sorry for the late reply Thanks! |
Thank you for your reply. |
@rohitsharmahub the please, share a snippet of your code to review it! |
Hi @AsemAlalami , Thanks for looking into my issue, Please find the code snippet. i am trying to plot the data into table via this method setTableData() but it does not reflect the passed data on table.
|
If am doing it in a wrong way then it would be great if you could share some pieces of code for this task. |
@rohitsharmahub I think you trying to use the constructor () {
// API url
this.url = `${apiBaseUrls}dataapi`
this.checkAllInput = (
<input
type='checkbox'
ref={this.check_all}
onChange={this.handleCheckboxTableAllChange}
/>
);
this.columns = [
'id',
....
];
this.options = {
headings: {
.....
},
sortable: [
.....
],
columnsAlign: {
....
},
icons: {
....
},
texts: {
....
},
responseAdapter: (resp_data) => {
console.log(resp_data);
let usersIDs = resp_data.data.map((a) => +a.id);
this.setState({ usersIDs: usersIDs }, () => {
this.check_all.current.checked =
_.difference(this.state.usersIDs, this.state.selectedUsers)
.length === 0;
});
return { data: resp_data.data, total: resp_data.total };
},
};
}
}
render() {
let self = this;
<ServerTable
columns={this.columns}
url={this.url}
options={this.options}
bordered
hover
>
{(row, column) => {
switch (column) {
case 'id':
return (
<input
key={+row.id}
type='checkbox'
value={+row.id}
onChange={self.handleCheckboxTableChange}
checked={self.state.selectedUsers.includes(
+row.id
)}
/>
);
default:
return row[column];
}
}}
</ServerTable>
} |
Thank you @AsemAlalami :) |
I created my own search bar rather than using inbuilt search from this table. Now I am looking to pass my server response having exact required format to this Table so i could populate the data over it.
Any comment will be helpful for me. Thanks
The text was updated successfully, but these errors were encountered: