Format Data for display and add edit delete buttons on server side script
Format Data for display and add edit delete buttons on server side script
Hello everyone,
I just want to retrieve columns and convert a column value 1 to "Active" and "Not Active" for empty and null value.
- I would like to add edit and delete button and assing the record value to this button, for crud purpose.
Code below : Server side script
$primaryKey = 'id';
$columns = array(
array( 'db' => 'first_name', 'dt' => 0 ),
array( 'db' => 'last_name', 'dt' => 1 ),
array( 'db' => 'address', 'dt' => 2 ),
array( 'db' => 'phone', 'dt' => 3,),
array( 'db' => 'status', 'dt' => 4,,
'formatter' => function( $d, $row ) {
//Not sure what to do here my status field might contain 1 or null or empty as a value and I would like to say 1 = "Active" and null or empty to "Not Active". can i also make this value background as red and green.
}
array( 'db' => 'date_of_birth','dt' => 6,
'formatter' => function( $d, $row ) {
return date( 'd-m-Y', strtotime($d));
Further at each row, I would like to show edit, delete buttons with glyphicons and assign the record value, so once clicked it opens the respective record in a modal window.
}
)
);
This question has an accepted answers - jump to answer
Answers
something like this
I found some more relevant information, where i can change the background color to anything using jquery, but still unable to find how i can use if condition and change he value of the column.
. warning {
background-color: #F99 !important;
}
I am getting closer. still need some help.
.data-table-container {
padding: 10px;
}
.dt-buttons .btn {
margin-right: 3px;
}
more closer..
data_replace = data.replace(/\//g, '_');
"columnDefs": [ {
"targets": 3,
"createdCell": function (td, cellData, rowData, row, col) {
if ( cellData == "Active" ) {
$(td).css('color', 'green')
}
if ( cellData == "Inactive") {
$(td).css('color', 'red')
}
}
} ]
@allan need some help please.
I am almost there, now i would like to do two things. one replace the value to active and change the background color of the return column
Finally I reached to this point where i can get active and not active. but
return data i would like to set in a label.
@Allan to the rescue
Any suggestion is highly appreciated.
Its a bit confusing where you are at and what you are trying to do. Maybe you can post a test case with a description of what you want to do.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin