Creating a Column using an existing column but using a substring
Creating a Column using an existing column but using a substring
MystaAvalon
Posts: 1Questions: 1Answers: 0
I have DataTables using an API pull.
The data from the API comes in with pipes (|) between each value in Field3 and I need to break them apart. For example:
{
"Field1":"Value1",
"Field2":"Value2",
"Field3":"Value3|Value4|Value5|Value6" // Example: Apple|Orange|Grape|Banana
}
I would like to break the data up in the DataTables call
$(document).ready(function(){
$('#table').DataTable({
data: snarf,
columns: [
{ data: 'Field1' },
{ data: 'Field2' },
{ data: 'Field3' } // Using Value3 from Field3 Example: Apple
{ data: 'Field3' } // Using Value4 from Field3 Example: Orange
{ data: 'Field3' } // Using Value5 from Field3 Example: Grape
{ data: 'Field3' } // Using Value6 from Field3 Example: Banana
]
});
});
Can anyone guide me through the render process that can pull the substring I need for each?
Any help would be appreciated.
-L
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can use
columns.render
for this. For example:http://live.datatables.net/yetugepu/1/edit
You may want to add some if statements to make sure the
split()
function works as expected.Kevin