Closed cod3rshotout closed 2 years ago
I was testing the $dt->showCheckboxes() which is working well, but imho we should add the data id of the row, in this way we can store the correct record reference, code is better than any words:
$dt->showCheckboxes()
public function getColumns() { $columns = $this->columns(); if ($this->checkboxes) { $cbid = uniqid('checkbox_'); array_unshift($columns, Column::add( '<div class="icheck-primary mb-0 mt-0"> <input type="checkbox" name="dt-check-all" id="' . $cbid . '" autocomplete="off"> <label for="' . $cbid . '"></label> </div>' ) ->notSearchable() ->notOrderable() ->data('checkbox', function ($data) { $id = uniqid('checkbox_'); $name = isset($data['id']) ? 'dt-checkbox[' . $data['id'] . ']' : 'dt-checkbox[]'; return '<div class="icheck-primary mb-0"> <input type="checkbox" name="' . $name . '" id="' . $id . '" autocomplete="off"> <label for="' . $id . '"></label> </div>'; })); } return $columns; }
As you can see I check if $data have the id, then I assign for each checkbox the id of the record. When sent a post request, I will get:
$data
Which represent the id of the rows selected, this id is associated can be associated to a pk of a table.
What do you think about it?
Id is now added by default as the reference to dt-checkbox.
But you can also use another field as reference if needed : see documentation here
I was testing the
$dt->showCheckboxes()
which is working well, but imho we should add the data id of the row, in this way we can store the correct record reference, code is better than any words:As you can see I check if
$data
have the id, then I assign for each checkbox the id of the record. When sent a post request, I will get:Which represent the id of the rows selected, this id is associated can be associated to a pk of a table.
What do you think about it?