select field (using Ajax loaded data) to load dynamically the pair: label, value

select field (using Ajax loaded data) to load dynamically the pair: label, value

aneto2400aneto2400 Posts: 58Questions: 8Answers: 1

Hi Allan,

I´m using v.1.6.2 of DT Editor ( JS+PHP).

About the last example of the page https://editor.datatables.net/reference/field/select .

In the example it says that it is for standalone mode, but I am using that code with the normal mode of Editor (not standalone mode) and the code itself correctly returns the pair (label, value) but when editing one of the rows, the value of the field select is not the one it had, is the first one that returns the getJSON.

Then when you press the Update button it saves that value (the first one that came from the JSON), not the one it had previously.

Is there a way to use this example in normal Editor mode (not standalone) and that it works?

I need to load the pair (name, letter_id) that comes from the JSON (below) into the pair (label, value) of the select field (this works) and after when you EDIT a row, that field is not automatically overwritten for the first that came on JSON (this is the trouble )

Any idea?

Thank you in advance,
Eduardo

My code - very similar to the example - :

````

    var optionsA = [];

    function returnNameCarta() {

        $.getJSON(parser_origin + parser_root_php + "/php/getDropDownList.php", {
                site: id_establecimiento()
            },
            function(data) {
                var option = {};
                $.each(data, function(i, e) {
                    option.label = e.name;
                    option.value = e.id_carta;
                    optionsA.push(option);
                    option = {};
                });
            }
        ).done(function() {
            editor.field( 'name_carta' ).update( optionsA ); // important

        });
    };
        fields: [ 
            {
                label: "Carta Seleccionada:",
                name: "name_carta", 
                type: "select",
                options: returnNameCarta(),
            },
                  ....

        

JSON OUTPUT:

0: {DT_RowId: "row_122", name: "Carta Principal", id_carta: "1"}
1: {DT_RowId: "row_123", name: "Carta de Postres", id_carta: "2"}
2: {DT_RowId: "row_124", name: "Carta de Vinos", id_carta: "3"}
3: {DT_RowId: "row_127", name: "Carta de Cócteles", id_carta: "6"}

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi Eduardo,

    The first thing to do would be to upgrade to Editor 1.9.4 and see if that helps, as I do remember putting in some code to help address this sort of thing, although I can’t remember which version it went into.

    Failing that, can you give me a link to a page showing the issue so I can debug it please?

    Allan

  • aneto2400aneto2400 Posts: 58Questions: 8Answers: 1

    Thank you for you help. Ok, first I going to upgrade to 1.9.4 and if continue de issue I will contact again. Greetings!

This discussion has been closed.