use selected only specfic rows from ajax response and group them
use selected only specfic rows from ajax response and group them
i'm using ajax to populate my table, what i need is to select only some rows of the ajax response, and group some, something like this:
AJAX response:
{
"draw": 1,
"recordsTotal": 10,
"recordsFiltered": 10,
"data": [
{
"id": 1,
"name": "Nba youngboy",
"phone1": "123",
"phone2": "456",
"phone3": null,
"phone4": null,
"phone5": null,
"email1": "nbayoung@email.com",
"email2": "nbayoungboi@hotmail.com",
"email3": "youngnigga@mail.com",
"email4": null,
"email5": null,
"notations": "gang shit",
"created_at": "2018-07-01 00:25:35"
},
the table has name, email, phone and notations as rows, what i want to do is to group the non empty rows as one, for eg:
phone1 and phone2 aren't empty, so they became only 'email', "email:"phone1<br>phone2", and the same goes for email, "email":"nbayoung@email.com<br>nbayoungboi@hotmail.com<br>youngnigga@mail.com", its possible to do it?
current settings:
$(".datatable-ajax").dataTable({
"processing" : true,
"serverSide" : true,
"order" : [],
"ajax" : {
url:"",
type:"POST"
}
sorry for my bad english.
Answers
You can use an extension for grouping:
https://datatables.net/extensions/rowgroup/
To show only some rows and filter them according to your own criteria you can use
"$.fn.dataTable.ext.search.push"
https://datatables.net/manual/plug-ins/search#Example
https://datatables.net/blog/2014-08-26#Complete-code