pass to the editor ajax function a compound key

pass to the editor ajax function a compound key

ciccocicco Posts: 3Questions: 2Answers: 0
edited May 2019 in Free community support

Hi,
I'm doing the first tests with the editor (trial).

I have a problem with the key to pass to the edit function because I have a compound key.

this is the initialization function of my datatable

$('#mytable').dataTable({
        select: true,   
        dom: '<"top"i>rt<"bottom"Blp><"clear">', 
        serverSide: true,  
        processing: true,
        ajax: {
            url: '/Controller/jquery_datatable_get',
            type: 'POST',
            datatype: "json"
        },
        columns: [
            {
                data: null, "orderable": false,
                render: function (data, type, row) {
                    return data.YEAR + '_' + data.NUMBER;
                }
            },
            { data: "YEAR", "orderable": true },
            { data: "NUMBER", "orderable": false },
            { data: "QTY", "orderable": false },

And this is the initialization function of my editor

var editor_mine = new $.fn.dataTable.Editor({
        table: '#mytable',
        idSrc: 'NUMBER',
        ajax: {
            edit: {
                type: 'POST',
                url: '/Controller/jquery_datatable_editor?id=_id_'
            }
        },
        fields: [
            { label: "quantity", name: "QTY" }
            ]
    });

With these functions I can pass the NUMBER id to my edit function but this is not my goal. Instead I have to pass a combination of the YEAR and NUMBER fields which are my compound key.
In the datatable initialization function, I put an example of this key as data.YEAR + '_' + data.NUMBER, but it can be anything else that allows me to detect the different 2 values.
How should I do?

Thanks
Andrea

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Answer ✓

    Hi Andrea,

    On the client-side, Editor currently only works with a combined company key value - e.g. 2019_1 in this case. The reason for this, as you've seen above is that idSrc option can only point at a single parameter. You'd need to have the server-side provide a combined field for the key, or otherwise join the two data points together before given to the DataTable.

    Allan

  • ciccocicco Posts: 3Questions: 2Answers: 0

    ok Allan. Thanks

This discussion has been closed.