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:
The rows prop 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 unique id field available on it.



headers:
The headers prop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, where key is the name of the key in a row object, and header is 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










share|improve this question
























  • 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: 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

















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:
The rows prop 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 unique id field available on it.



headers:
The headers prop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, where key is the name of the key in a row object, and header is 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










share|improve this question
























  • 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: 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















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:
The rows prop 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 unique id field available on it.



headers:
The headers prop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, where key is the name of the key in a row object, and header is 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










share|improve this question















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:
The rows prop 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 unique id field available on it.



headers:
The headers prop represents the order in which the headers should appear in the table. We expect an array of objects to be passed in, where key is the name of the key in a row object, and header is 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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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




















  • 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: 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


















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














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
}
})





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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
    }
    })





    share|improve this answer

























      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
      }
      })





      share|improve this answer























        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
        }
        })





        share|improve this answer












        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
        }
        })






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        charlietfl

        137k1285118




        137k1285118






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Sphinx de Gizeh

            Dijon

            Guerrita