You can use this method to start creating a new column.
you can pass db_column_name or whatever name you need to the column method, if you pass the db_column_name it will return the data of that column.
you can also access the nested data using .
for example column("name.en")
$datatable->column("updated_at")->date("YYYY-MM-DD");
$datatabl->column("created_at", function ($row) {
return $row->created_at->diffForHumans();
})->sortable()->searchable();
// render column if condition true
$datatable->column(function() {
if (true) {
return "status";
}
});
You can use this method to make column is sortable.
this method accepts one boolean argument by default it's true.
$datatable->column("updated_at")->sortable(false);
You can use this method to make column is searchable.
this method accepts one boolean argument by default it's true.
$datatable->column("updated_at")->searchable(false);
This method must be used to make the column visible while the page is being printed and in export files.
this method accepts one boolean argument by default it's true.
$datatable->column("name")->exportable();
You can use this method to make date columns more readable default is human format Optionally you can pass any format to date method.
$datatable->column("date")->date("YYYY-MM-DD", "Invalid Date");
You can use this method to show column in html img tag.
the image src will be the value of the db_column.
you can pass any value to this method and that value will be applied before the value of the db_column.
$datatable->column("image")->image("images/|id|/");
if you want to access any field value just write that field between two columns || |created_at|
you can use this method to set href to the column.
$datatable->column("image")->href("|id|/|category.name.en|", '_blank');
if you want to access any field value just write that field between two columns || |created_at|
You can use this method to create clone, edit and delete actions buttons, and you can optionally pass the given column label to the method the default label will be set from the column name.
$datatable->column("actions")->actions();
You can use this method to enable all rows to be selected for deletion at once, and you can optionally pass the given column label to the method the default label will be set from the column name.
$datatable->column("select")->checkall();
you can use these methods to execute any javascript code
.
by default it will return the whole code you wrote in it , if you want to return specfic data you will need to write return
before it.
in these methods if field you are going to write between two columns || is not number then you must enclose it in double quotes "|created_at|"
$datatable->column("custom_one")
->jsToHtml(
<<<JS
|status| == 1
? '<span class="badge bg-success"> Active </span>'
: '<span class="badge bg-danger"> InActive </span>'
JS
);
// add column html with condition
$datatable->column("custom_one")
->jsToHtml(
<<<JS
let deleted_at = "|deleted_at|";
// you can write any JS code here
return deleted_at
? false
: '|id|'
JS
);
$datatable->column("custom_one")->jsToHref('/|id|');