There is a better way to put a dropdown in your cells. Of course, this is searchable. You can see the official manual about this technique.
Client side
Create a list down
When you initialize the plugin, you can do this:
<script type="text/javascript"> $(document).ready(function () { $('#datatable').dataTable().makeEditable({ sUpdateURL: "UpdateData.php",
A key is a piece of data. Here you can define the parameters of your list. You can also add this part dynamically through PHP. The syntax is as follows for one parameter.
'variable_sent_to_UpdateData.php':'Text that will be displayed'
Each option must be separated by a comma.
Column names
You can also rename your columns, as shown in the official guide , so when they are transferred to the server, DataTables will not name them after the <th> :
<script type="text/javascript"> $(document).ready(function () { $('#datatable').dataTable( aoColumns: [
Server side
In the end, you just need to update your database in UpdateData.php :
$id = $_REQUEST['id'];
It is important to echo (return) the $value variable because:
- Indicates that the update was successful.
- This value will be the new value in the table.
- If you return something else, it will be considered an error message that will be displayed in a pop-up window and no changes to the table will be shown.
source share