Editor script on changed value

Editor script on changed value

ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
edited February 19 in Editor

I have a table set up like this (simplified for the exemple):

var editor = new DataTable.Editor({
    idSrc: "NUMBER",
    fields: [
        {
            "label": "Ready",
            "name": "Ready",
            "type": "select",
            options:   [
                { label: '✖', value: null },
                { label: '✔', value: '1' }, 
            ]
        },
table: "#exemple"
});

var table = new DataTable("#cloture", {
language: {
        url: staticUrl,
    },
    ajax: {
        url: 'myjsonurl',
        type: "GET",
        dataType: "json",
        dataSrc: '',
    },
    buttons: [
        { extend: "searchBuilder", className: "buttons-searchBuilder w-100 h-100 p-3" },
        { extend: "edit", className: "w-100 h-100 p-3", editor },   
    ],
columns: [
        // DOSSIER PERMANENT
            { data: "NUMBER", name:"NUMBER" },
            { data: "NAME", name:"NAME" },
            { data: "ADRESS", name:"ADRESSE" },
            { data: "READY", name:"READY", className: "editable", 
                render: function (data, type){
                    if (type === "display"){
                        if (data == null) {
                            return "✖";
                        } else if (data == "1") {
                            return "✔";
                        }
                    } else if (type === "sort" || type === 'filter' ){
                        if (data == null) {
                            return '0';
                        } else if (data == "1") {
                            return "1";
                        }
                    }
                    return data;
                }
            },
dom: "Bfrtip",
    select: true,
    processing: true,
    deferRender: true,
    scrollX: true,
    pageResize: true,

});

What i want to do is send a mailto when the data in the "READY" column is changed. The bellow script isn't trigger, can you help me to trigger this script when the data in the ready column is send / changed.

$('#exemple').on( 'change', 'td:nth-child(4)', function () {
    var rowData = table.row($(this).closest('tr')).data();
     var BilanPret = rowData['READY'];
    if (BilanPret == 1) {
        // send the mailto here
        console.log('test)  
    }
});

Thank for your time / answer,
Mathieu.

Edited by Allan - syntax highlighting

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,602Questions: 1Answers: 10,486 Site admin

    Hi Mathieu,

    td cells don't trigger a change event. input elements do, but not other elements.

    Listen for Editor's submitComplete event and trigger your e-mail there.

    Allan

  • ECEGROUPEECEGROUPE Posts: 78Questions: 29Answers: 1
    edited February 19

    Hi Allan,

    Thank for your answers :smile:, it almost work, is it possible to get value of row / cell in submitComplete function ?

    editor.on('submitComplete', function (e, json, data, action) {
    
    // send mail here but only when user change the column READY (assuming there is other editable column) and if the new value of ready column is 1
    
    }
    
  • kthorngrenkthorngren Posts: 21,391Questions: 26Answers: 4,961
    Answer ✓

    The json parameter has the JSON data returned from the server, possibly you can use that. Or the data parameter has the data sent to the server. Do either of these contain what you are looking for.

    Kevin

Sign In or Register to comment.