string joining
string joining
Hello,
Can't seem to hack this out, so I am a wee bit embarrassed to inquire what I could be doing wrong.
I have a bash script to generate data in a json file that I wish to deliver to users via a web page.
I want to join some data elements together since we don't need to have twenty columns of data scrolling across the screen, but I still want to keep the data normalized for future proofing the data.
For the record, I have followed the examples given on:
https://www.datatables.net/examples/advanced_init/column_render.html
https://datatables.net/manual/data/renderers#Functions
Some work , others don't
This is what I have:
$(document).ready(function() {
$('#Report_table').DataTable( {
"ajax": {
"url": "http://__URL__/__PATH__/__FILE__.json",
"dataSrc": ""
},
"columnDefs": [
{ "targets": 0, "render": function ( data, type, full, meta ) { return type === 'display' && data.length > 40 ? '<span title="'+data+'">'+data.substr(0,38)+'...</span>' : data; } },
{ "targets": 1, "render": function ( data, type, full, meta ) { return '<a href="http://www.google.com/webhp?q='+data+'" target="_blank">'+data+'</a>'; } },
{ "targets": 2, "render": function ( data, type, row ) { return data + '<br>' + data[3]; }, },
],
"columns": [
{ "data": "Column_A" },
{ "data": "Column_B" },
{ "data": "Column_C" },
{ "data": "Column_D" },
]
} );
} );
// $.fn.dataTable.ext.errMode = 'none';
Results:
Column_A | Column_B | Column_C | Column_D
Data Data Data Data
undefined <----- this should show Column_D's data
This question has an accepted answers - jump to answer
Answers
I'd suggest you merge your
columnDefs
andcolumns
arrays together - I think its just an extra level of indirection splitting them up and only using a single target for each def. e.g.:Having said that, you are telling column index 2 to get the data from
Column_C
and then using:data[3]
- that would be the same asColumn_C[3]
.Is
Column_C
always an array, and do you actually want the fourth element from it every time?Allan
Thank you Allan for your response.
For now, as I am still learning how to use Datatables, my plan is to keep things separated until I understand Datatables better.
if I am understanding your question at the end, in my json file, each row of data is an array.
The way that I am thinking of this problem is akin to Excel. I want to take the data from C1, D1 and join them in cell C1, and then hide cell D1.
Using my example json data, my output should be:
which is basically the same as:
since
data
points to theColumn_C
property.Allan
Ding! Ding! Ding!
We have a winner. Thank you Allan.
Now, my final question to you is this:
How can I help you improve on your documentation to assist others?
Tell me where you think it needs to be improved! The rendering page covers this, but is there anything missing?
Allan