Closed ChakraKBBala closed 5 years ago
Hello! Is it any different with the examples in https://github.com/Imballinst/react-bs-datatable#example-usage? Basically this should do:
const header = [
{ title: 'Serial Number', prop: 'serialNumber' },
];
const body = [
{
serialNumber: 'BBBB-XXXX-WWWW' },
{
serialNumber: 'BBBB-XXXX-YYYY'
}
];
<Datatable
tableHeader={header}
tableBody={body}
/>
If your use case is different -- e.g. there is more than that, please do let me know.
Thanks for your response @Imballinst , But i need to add a auto-increment number for each row
eg:
Let's see if I get your requirement right:
(1) name
, age
, and gender
data field exists, such as:
[
{ name: 'XXX', age: 1, gender: 'YYY' },
{ name: 'YYY', age: 12, gender: 'XXX' },
{ name: 'ZZZ', age: 4, gender: 'YZCX' },
]
and (2) you do not want to manually add, say, sNo
field to each of the array element?
If that is what you mean, it is not available at the moment -- but I can make a quick PR and sample how to use it in CodeSandbox if you want.
@Imballinst Correct.., i don't have s.no filed in my array element i want to create it manually from front-end
Gotcha. I'll let you know tonight/tomorrow morning!
Hey @ChakraKBBala, just to make sure, does this not fulfill your need?
const arrayWithoutSerialNumber = [
{ name: 'XXX', age: 1, gender: 'YYY' },
{ name: 'YYY', age: 12, gender: 'XXX' },
{ name: 'ZZZ', age: 4, gender: 'YZCX' },
];
const yourArray = arrayWithoutSerialNumber.map((arr, idx) => ({ ...arr, sNo: idx + 1 });
// Now your array looks like below.
console.log(yourArray);
[
{
"name": "XXX",
"age": 1,
"gender": "YYY",
"sNo": 1
},
{
"name": "YYY",
"age": 12,
"gender": "XXX",
"sNo": 2
},
{
"name": "ZZZ",
"age": 4,
"gender": "YZCX",
"sNo": 3
}
]
Just in case, so I do not implement something too-complex.
I thought not to add s.no field into that array elements, anyways if it is too complex to implement then i can use this map method. Thanks :) @Imballinst
I see. Yeah, from my point of view, the complexity rises when you combine it with sort and pagination -- e.g.
for (let i = data.length - 1; i >= 0; i -= 1)
instead of for (let i = 0; i < data.length; i += 1)
startID: (page * rowsPerPage) + 1
and ends with endID: (page * rowsPerPage) + rowsPerPage
Thank you for your understanding, though! Feel free to re-open this issue if you have further queries.
Can you please tell me how to add serial number for each row