How can I model data for a datable?
up vote
-1
down vote
favorite
I have a datatable where I am using a framework.
For now I am only mocking data because I don't have straight directions from my boss yet.
In the datatable docs say this:
rows:
Therowsprop is where you provide us with a list of all the rows that you want to render in the table. The only hard requirement is that this is an array of objects, and that each object has a uniqueidfield available on it.
headers:
Theheadersprop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, wherekeyis the name of the key in a row object, andheaderis the name of the header.
The headers are going to be hardcoded:
For that I have this:
const tableHeaders = [
{
key: 'device',
header: t('cancellations.device'),
},
{
key: 'ticketNumber',
header: t('cancellations.ticketNumber'),
},
{
key: 'itemsCancelled',
header: t('cancellations.itemsCancelled'),
},
{
key: 'requestDate',
header: t('cancellations.requestDate'),
},
{
key: 'status',
header: t('cancellations.status'),
},
{
key: 'requestedBy',
header: t('cancellations.requestedBy'),
},
];
And before I had this hardcoded which is what I need to model and keep it exactly as it is, not hardcoded but with real data:
const rows = [
{
id: 'a',
device: t('Device 1'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'b',
device: t('Device 2'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'c',
device: t('Device 3'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
}
];
And the real data comes like this:
"CancellationRequests": [
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-18T11:28:47-07:00",
"id": 17195077,
"modifyDate": "2018-09-18T11:28:48-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65626859,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
},
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-10T11:11:05-07:00",
"id": 17183859,
"modifyDate": "2018-09-10T11:11:06-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65169379,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
}
]
So, comparing the real data with the hardcoded rows, it should match like this:
id: row.id,
device: row.account,
ticketNumber: row..ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user,
I am getting the values like this:
data.SoftLayerCancellationRequests.map(item => item);
But I don't know how to assign them to the proper key: value in a new object.
PS: I am using Reactjs.
Library use for components: http://react.carbondesignsystem.com/?selectedKind=DataTable&selectedStory=with%20expansion&full=0&addons=1&stories=1&panelRight=0&addonPanel=REACT_STORYBOOK%2Freadme%2Fpanel
javascript arrays reactjs ecmascript-6
|
show 3 more comments
up vote
-1
down vote
favorite
I have a datatable where I am using a framework.
For now I am only mocking data because I don't have straight directions from my boss yet.
In the datatable docs say this:
rows:
Therowsprop is where you provide us with a list of all the rows that you want to render in the table. The only hard requirement is that this is an array of objects, and that each object has a uniqueidfield available on it.
headers:
Theheadersprop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, wherekeyis the name of the key in a row object, andheaderis the name of the header.
The headers are going to be hardcoded:
For that I have this:
const tableHeaders = [
{
key: 'device',
header: t('cancellations.device'),
},
{
key: 'ticketNumber',
header: t('cancellations.ticketNumber'),
},
{
key: 'itemsCancelled',
header: t('cancellations.itemsCancelled'),
},
{
key: 'requestDate',
header: t('cancellations.requestDate'),
},
{
key: 'status',
header: t('cancellations.status'),
},
{
key: 'requestedBy',
header: t('cancellations.requestedBy'),
},
];
And before I had this hardcoded which is what I need to model and keep it exactly as it is, not hardcoded but with real data:
const rows = [
{
id: 'a',
device: t('Device 1'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'b',
device: t('Device 2'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'c',
device: t('Device 3'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
}
];
And the real data comes like this:
"CancellationRequests": [
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-18T11:28:47-07:00",
"id": 17195077,
"modifyDate": "2018-09-18T11:28:48-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65626859,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
},
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-10T11:11:05-07:00",
"id": 17183859,
"modifyDate": "2018-09-10T11:11:06-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65169379,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
}
]
So, comparing the real data with the hardcoded rows, it should match like this:
id: row.id,
device: row.account,
ticketNumber: row..ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user,
I am getting the values like this:
data.SoftLayerCancellationRequests.map(item => item);
But I don't know how to assign them to the proper key: value in a new object.
PS: I am using Reactjs.
Library use for components: http://react.carbondesignsystem.com/?selectedKind=DataTable&selectedStory=with%20expansion&full=0&addons=1&stories=1&panelRight=0&addonPanel=REACT_STORYBOOK%2Freadme%2Fpanel
javascript arrays reactjs ecmascript-6
It looks like the framework is not specified in your post, it might be helpful to include that info in your post. Currently you have a lot of data, but no real info what you have tried already
– Icepickle
yesterday
Hi @Icepickle I added a reference to the component I am using to the post: react.carbondesignsystem.com/…
– TheUnnamed
yesterday
true, but the page you link to has a great amount of sample code, which matches almost one to one with the data you provided here, so once again, where would your problem be?
– Icepickle
yesterday
@Icepickle I don't know how to assign them to the properkey: valuein a new object. So I can send the proper prop already modeled.
– TheUnnamed
yesterday
As far as I can see, the datatable does that work for you, you simply provide it with rows and headers, and it will map cells with an id and a value property. And the data as you have it, is already perfect for how the datatable expects it
– Icepickle
yesterday
|
show 3 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a datatable where I am using a framework.
For now I am only mocking data because I don't have straight directions from my boss yet.
In the datatable docs say this:
rows:
Therowsprop is where you provide us with a list of all the rows that you want to render in the table. The only hard requirement is that this is an array of objects, and that each object has a uniqueidfield available on it.
headers:
Theheadersprop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, wherekeyis the name of the key in a row object, andheaderis the name of the header.
The headers are going to be hardcoded:
For that I have this:
const tableHeaders = [
{
key: 'device',
header: t('cancellations.device'),
},
{
key: 'ticketNumber',
header: t('cancellations.ticketNumber'),
},
{
key: 'itemsCancelled',
header: t('cancellations.itemsCancelled'),
},
{
key: 'requestDate',
header: t('cancellations.requestDate'),
},
{
key: 'status',
header: t('cancellations.status'),
},
{
key: 'requestedBy',
header: t('cancellations.requestedBy'),
},
];
And before I had this hardcoded which is what I need to model and keep it exactly as it is, not hardcoded but with real data:
const rows = [
{
id: 'a',
device: t('Device 1'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'b',
device: t('Device 2'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'c',
device: t('Device 3'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
}
];
And the real data comes like this:
"CancellationRequests": [
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-18T11:28:47-07:00",
"id": 17195077,
"modifyDate": "2018-09-18T11:28:48-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65626859,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
},
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-10T11:11:05-07:00",
"id": 17183859,
"modifyDate": "2018-09-10T11:11:06-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65169379,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
}
]
So, comparing the real data with the hardcoded rows, it should match like this:
id: row.id,
device: row.account,
ticketNumber: row..ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user,
I am getting the values like this:
data.SoftLayerCancellationRequests.map(item => item);
But I don't know how to assign them to the proper key: value in a new object.
PS: I am using Reactjs.
Library use for components: http://react.carbondesignsystem.com/?selectedKind=DataTable&selectedStory=with%20expansion&full=0&addons=1&stories=1&panelRight=0&addonPanel=REACT_STORYBOOK%2Freadme%2Fpanel
javascript arrays reactjs ecmascript-6
I have a datatable where I am using a framework.
For now I am only mocking data because I don't have straight directions from my boss yet.
In the datatable docs say this:
rows:
Therowsprop is where you provide us with a list of all the rows that you want to render in the table. The only hard requirement is that this is an array of objects, and that each object has a uniqueidfield available on it.
headers:
Theheadersprop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, wherekeyis the name of the key in a row object, andheaderis the name of the header.
The headers are going to be hardcoded:
For that I have this:
const tableHeaders = [
{
key: 'device',
header: t('cancellations.device'),
},
{
key: 'ticketNumber',
header: t('cancellations.ticketNumber'),
},
{
key: 'itemsCancelled',
header: t('cancellations.itemsCancelled'),
},
{
key: 'requestDate',
header: t('cancellations.requestDate'),
},
{
key: 'status',
header: t('cancellations.status'),
},
{
key: 'requestedBy',
header: t('cancellations.requestedBy'),
},
];
And before I had this hardcoded which is what I need to model and keep it exactly as it is, not hardcoded but with real data:
const rows = [
{
id: 'a',
device: t('Device 1'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'b',
device: t('Device 2'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
},
{
id: 'c',
device: t('Device 3'),
ticketNumber: t('Ticket Number'),
itemsCancelled: t('Items Cancelled'),
requestDate: t('Request Date'),
status: t('Status'),
requestedBy: t('Requested By'),
}
];
And the real data comes like this:
"CancellationRequests": [
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-18T11:28:47-07:00",
"id": 17195077,
"modifyDate": "2018-09-18T11:28:48-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65626859,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
},
{
"accountId": 232279,
"billingCancelReasonId": null,
"createDate": "2018-09-10T11:11:05-07:00",
"id": 17183859,
"modifyDate": "2018-09-10T11:11:06-07:00",
"notes": null,
"statusId": 2,
"ticketId": 65169379,
"account": null,
"items": null,
"status": null,
"ticket": null,
"user": null,
"itemCount": null,
"__typename": "SoftLayer_Billing_Item_Cancellation_Request"
}
]
So, comparing the real data with the hardcoded rows, it should match like this:
id: row.id,
device: row.account,
ticketNumber: row..ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user,
I am getting the values like this:
data.SoftLayerCancellationRequests.map(item => item);
But I don't know how to assign them to the proper key: value in a new object.
PS: I am using Reactjs.
Library use for components: http://react.carbondesignsystem.com/?selectedKind=DataTable&selectedStory=with%20expansion&full=0&addons=1&stories=1&panelRight=0&addonPanel=REACT_STORYBOOK%2Freadme%2Fpanel
javascript arrays reactjs ecmascript-6
javascript arrays reactjs ecmascript-6
edited yesterday
asked yesterday
TheUnnamed
1,26021126
1,26021126
It looks like the framework is not specified in your post, it might be helpful to include that info in your post. Currently you have a lot of data, but no real info what you have tried already
– Icepickle
yesterday
Hi @Icepickle I added a reference to the component I am using to the post: react.carbondesignsystem.com/…
– TheUnnamed
yesterday
true, but the page you link to has a great amount of sample code, which matches almost one to one with the data you provided here, so once again, where would your problem be?
– Icepickle
yesterday
@Icepickle I don't know how to assign them to the properkey: valuein a new object. So I can send the proper prop already modeled.
– TheUnnamed
yesterday
As far as I can see, the datatable does that work for you, you simply provide it with rows and headers, and it will map cells with an id and a value property. And the data as you have it, is already perfect for how the datatable expects it
– Icepickle
yesterday
|
show 3 more comments
It looks like the framework is not specified in your post, it might be helpful to include that info in your post. Currently you have a lot of data, but no real info what you have tried already
– Icepickle
yesterday
Hi @Icepickle I added a reference to the component I am using to the post: react.carbondesignsystem.com/…
– TheUnnamed
yesterday
true, but the page you link to has a great amount of sample code, which matches almost one to one with the data you provided here, so once again, where would your problem be?
– Icepickle
yesterday
@Icepickle I don't know how to assign them to the properkey: valuein a new object. So I can send the proper prop already modeled.
– TheUnnamed
yesterday
As far as I can see, the datatable does that work for you, you simply provide it with rows and headers, and it will map cells with an id and a value property. And the data as you have it, is already perfect for how the datatable expects it
– Icepickle
yesterday
It looks like the framework is not specified in your post, it might be helpful to include that info in your post. Currently you have a lot of data, but no real info what you have tried already
– Icepickle
yesterday
It looks like the framework is not specified in your post, it might be helpful to include that info in your post. Currently you have a lot of data, but no real info what you have tried already
– Icepickle
yesterday
Hi @Icepickle I added a reference to the component I am using to the post: react.carbondesignsystem.com/…
– TheUnnamed
yesterday
Hi @Icepickle I added a reference to the component I am using to the post: react.carbondesignsystem.com/…
– TheUnnamed
yesterday
true, but the page you link to has a great amount of sample code, which matches almost one to one with the data you provided here, so once again, where would your problem be?
– Icepickle
yesterday
true, but the page you link to has a great amount of sample code, which matches almost one to one with the data you provided here, so once again, where would your problem be?
– Icepickle
yesterday
@Icepickle I don't know how to assign them to the proper
key: value in a new object. So I can send the proper prop already modeled.– TheUnnamed
yesterday
@Icepickle I don't know how to assign them to the proper
key: value in a new object. So I can send the proper prop already modeled.– TheUnnamed
yesterday
As far as I can see, the datatable does that work for you, you simply provide it with rows and headers, and it will map cells with an id and a value property. And the data as you have it, is already perfect for how the datatable expects it
– Icepickle
yesterday
As far as I can see, the datatable does that work for you, you simply provide it with rows and headers, and it will map cells with an id and a value property. And the data as you have it, is already perfect for how the datatable expects it
– Icepickle
yesterday
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You have already done all the hard work. It's just a matter of creating a new mapped array using your key matching already shown in your question
const rows = APIArray.map(row => {
return {
id: row.id,
device: row.account,
ticketNumber: row.ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user
}
})
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You have already done all the hard work. It's just a matter of creating a new mapped array using your key matching already shown in your question
const rows = APIArray.map(row => {
return {
id: row.id,
device: row.account,
ticketNumber: row.ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user
}
})
add a comment |
up vote
1
down vote
accepted
You have already done all the hard work. It's just a matter of creating a new mapped array using your key matching already shown in your question
const rows = APIArray.map(row => {
return {
id: row.id,
device: row.account,
ticketNumber: row.ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user
}
})
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You have already done all the hard work. It's just a matter of creating a new mapped array using your key matching already shown in your question
const rows = APIArray.map(row => {
return {
id: row.id,
device: row.account,
ticketNumber: row.ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user
}
})
You have already done all the hard work. It's just a matter of creating a new mapped array using your key matching already shown in your question
const rows = APIArray.map(row => {
return {
id: row.id,
device: row.account,
ticketNumber: row.ticketId,
itemsCancelled: row.itemCount,
requestDate: row.createDate
status: row.status,
requestedBy: row.user
}
})
answered yesterday
charlietfl
137k1285118
137k1285118
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401586%2fhow-can-i-model-data-for-a-datable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It looks like the framework is not specified in your post, it might be helpful to include that info in your post. Currently you have a lot of data, but no real info what you have tried already
– Icepickle
yesterday
Hi @Icepickle I added a reference to the component I am using to the post: react.carbondesignsystem.com/…
– TheUnnamed
yesterday
true, but the page you link to has a great amount of sample code, which matches almost one to one with the data you provided here, so once again, where would your problem be?
– Icepickle
yesterday
@Icepickle I don't know how to assign them to the proper
key: valuein a new object. So I can send the proper prop already modeled.– TheUnnamed
yesterday
As far as I can see, the datatable does that work for you, you simply provide it with rows and headers, and it will map cells with an id and a value property. And the data as you have it, is already perfect for how the datatable expects it
– Icepickle
yesterday