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

kuilachandankuilachandan Posts: 4Questions: 1Answers: 0
edited March 2019 in Free community support

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 }
        ]
    } );
} );

Answers

  • kthorngrenkthorngren Posts: 21,188Questions: 26Answers: 4,925

    Are you looking for something like this example?
    https://editor.datatables.net/examples/advanced/REST.html

    Kevin

  • kuilachandankuilachandan Posts: 4Questions: 1Answers: 0

    Thanks, I will check and inform you Kevin.

  • kuilachandankuilachandan Posts: 4Questions: 1Answers: 0

    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

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    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

  • kuilachandankuilachandan Posts: 4Questions: 1Answers: 0
    edited March 2019

    Hi @colin and @kthorngren I want like below attachment.
    Please give me some idea about it, I just attach the code sample.

  • allanallan Posts: 63,262Questions: 1Answers: 10,424 Site admin

    I'm afraid I'm a little confused as well. You say:

    am trying to get the raw data from data table and write custom ajax.

    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

This discussion has been closed.