How to do custom crud operation code in ajax URL instead of ajax: "../../controllers/staff
How to do custom crud operation code in ajax URL instead of ajax: "../../controllers/staff
kuilachandan
Posts: 4Questions: 1Answers: 0
Here is the sample code from Datatable :
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: "../../controllers/staff.php",
table: "#example",
fields: [ {
label: "First name:",
name: "first_name"
}, {
label: "Last name:",
name: "last_name"
}, {
label: "Position:",
name: "position"
}, {
label: "Office:",
name: "office"
}, {
label: "Extension:",
name: "extn"
}, {
label: "Start date:",
name: "start_date",
type: "datetime"
}, {
label: "Salary:",
name: "salary"
}
]
} );
$('#example').DataTable( {
dom: "Bfrtip",
ajax: "../../controllers/staff.php",
columns: [
{ data: null, render: function ( data, type, row ) {
// Combine the first and last names into a single table field
return data.first_name+' '+data.last_name;
} },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
],
select: true,
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
} );
} );
This discussion has been closed.
Answers
Are you looking for something like this example?
https://editor.datatables.net/examples/advanced/REST.html
Kevin
Thanks, I will check and inform you Kevin.
I am trying to get the raw data from data table and write custom ajax. Because a lot data process i will do in mysql by procedure. So, I do not want to use datatable inbuild create update delete api. How i fetch the data from templates? please help
Hi @kuilachandan ,
So, to be clear, you don't want to use Editor, you just want to use DataTables to send the data back to the server? If so, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi @colin and @kthorngren I want like below attachment.
Please give me some idea about it, I just attach the code sample.
I'm afraid I'm a little confused as well. You say:
In which can you don't need Editor. Use
rows().data()
to get the raw data from the DataTable and then do whatever you want with it (including sending it to the server).Allan