Reusing data to avoid repetition

Reusing data to avoid repetition

silkspinsilkspin Posts: 152Questions: 34Answers: 5

I'm wondering how to best approach a problem where I need to reuse values which aren't in the main data because there would be too much repetition. I pull the data in from a CSV using AJAX. What I need is something similar to how a 2 table database would work. So only an ID from the 2nd table needs to be entered in a cell in the main data. I can already achieve this using a JS file containing variables, and also using AJAX load from PHP files. I was thinking whether this could also be achieved by pulling data from a 2nd CSV file that is hidden from the front end. Is this something that is possible? I've not found any demos that might cover this type of set up and maybe there are other better ways of achieving it?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    Answer ✓

    One option might be to pull the CSV data into an object with the key being a unique data point that the main table data points to. Use columns.render to display the data. The row parameter can be used to get the full row data whcih you can then use to access the specific object data.

    Kevin

  • silkspinsilkspin Posts: 152Questions: 34Answers: 5

    Thanks @kthorngren. What I've decided on (and it works) was to put the variables in a PHP array. At the beginning of the index.php I've used "include" to add the array PHP file, and in the head tag I've assigned a JS var to the json_encode data. In my Datatable JS file I've used the render option to get the ID from the main DT data and pull in the corresponding array ID. This is now a really good way of maintaining repetitive data.

Sign In or Register to comment.