Editor datatable field type events - Need Help on How to address the field

Editor datatable field type events - Need Help on How to address the field

paul@dmcreative.compaul@dmcreative.com Posts: 21Questions: 4Answers: 0

I want to monitor the select and deselect events of an editor datatable field.

Reference is made to use the editor.field('name').dt() function to access the api.

Could someone please post the correct format to do this.

Assuming the following javascipt code what would be used at ??? so that the users.site field select event is being monitored

???.on('select' function() {
  alert('Row Selected');
} );
var editor; // use a global for the submit and return data rendering in the examples
 
$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "../php/join.php",
        table: "#example",
        fields: [ {
                label: "First name:",
                name: "users.first_name"
            }, {
                label: "Last name:",
                name: "users.last_name"
            }, {
                label: "Phone #:",
                name: "users.phone"
            }, {
                label: "Site:",
                name: "users.site",
                type: "datatable",
            }
        ]
    } );
 
    $('#example').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url: "../php/join.php",
            type: 'POST'
        },
        columns: [
            { data: "users.first_name" },
            { data: "users.last_name" },
            { data: "users.phone" },
            { data: "sites.name" }
        ],
        select: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ]
    } );
} );

Replies

  • colincolin Posts: 12,948Questions: 0Answers: 2,207

    You would use a DataTables API instance for that, so something like this: http://live.datatables.net/wayemiwe/1/edit

    Colin

  • paul@dmcreative.compaul@dmcreative.com Posts: 21Questions: 4Answers: 0

    Colin,

    You missed my question. I am asking about events in a datatable embedded in an editor form, NOT a normal standalone table.

    Please look at the sample javascript I referenced, and at the editor definition for users.site. It is users.site that I am trying to get to the select event.

    Thank you

    Paul

  • allanallan Posts: 54,909Questions: 1Answers: 8,606 Site admin

    Hi Paul,

    You can use the field().dt() method of the datatable field type to get the DataTable instance (it appears I forgot to add that into the docs - apologies, will add now):

    editor.field('users.site').dt().on('select', function () {
    
    } );
    

    Allan

  • paul@dmcreative.compaul@dmcreative.com Posts: 21Questions: 4Answers: 0

    Allan

    Exactly the information that I was looking for.

    Thank You

    Paul

Sign In or Register to comment.