updating database from use editable field
updating database from use editable field
wrestlerjake
Posts: 2Questions: 1Answers: 0
Hello, So i have a datatable being populated like i've shown below. However i need to update the database with the new userinput value when they click my update button. Currently i can have it show the new data but im not sure how to get it to update my sql table. I dont have editor so some options i saw that use editor im not able to do. I looked at forminput but its just outputting the changed data to the display which im able to do.
$(document).ready(function () {
var table = $('#example').DataTable({
serverSide: false,
language: {
searchBuilder: {
title: 'Custom Filter'
}
},
dom: 'Q<"pull-left"f><"pull-right"l>rtip',
ajax: {
url: "{{ url('/test') }}",
type: "GET",
datatype: "text",
data: {
q:"select * from exampleTable",
filename:"examplefile.json",
cacheInterval: 1
}
},
columns: [
{data: 'column1',title: 'column1'},
{data: 'column2',title: 'column2'},
{data: 'column3',title: 'column3'
"fnCreatedCell": function (nTd, oData) {
$(nTd).html("<input class='form-control' id='userInput' value='"+ oData.column3 +"'>");
}},
{ title: 'Update',
render: function (data, type, row) { return createButton('update',); }
}
],
order: [
[0, 'asc']
],
function createButton(buttonText, rowID) {
return '<button class= "btn btn-outline-primary" type="submit">' + buttonText+'</button>'; }
Answers
If you aren't using Editor, you'll need to have it make an Ajax call to the server that would call whatever script you write to update the database.
Allan
so inside my buttons on click function doing an ajax call to another script that would update?
When the user clicks the update button you will send the data to the server via an ajax request. The server will update the DB then return something indicating the update is complete. It could return a boolean value or maybe query for the updated row and return that data. In the success function you can simply use
ajax.relaod()
to refresh the table from the DB or update the particular row with the returned data.Kevin