How to get the value of dropdownlist generated dynamically in a table (datatables) with jquery

0

. Hello, I share this problem ... the data goes:

With this part of the function I load the data in a datatables.net and in the last row I render the selects with the data of the database:

        var objTipo = new Object();
        objTipo.id = $('#ddlTipoAuditoria').val();
        var datatable = $('#tableItemsAuditorias').DataTable({
            ajax: { 
                method: "POST",
                url: 'Auditoria.aspx/GetSubItemsAuditorias',
                //url: 'Auditoria.aspx/GetItemsAuditorias',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: function (d) { return JSON.stringify(objTipo); },
                dataSrc: "d.data"
            },
            "columns": [
                { "data": "idItem", "autoWidth": true, "visible": false },
                { "data": "nombreItem", "autoWidth": true },
                { "data": "idSubItem", "autoWidth": true, "visible": false },
                { "data": "nombre", "autoWidth": true },
                { "data": "idUM", "autoWidth": true, "visible": false },
                { 
                  "render": function (d, t, r, meta) {
                        var $select = $("<select class='tipo-unidad'></select>", {
                            "id": r[0] + "start",
                            "value": d
                        });
                        var modelo = models.data;
                        $.each(modelo, function (k, v) {
                            if (v.idUM == r.idUM) 
                            {
                                // Pregunta si el r.idUM (la unidad de medida que tiene el item es igual
                                // al tipo de uM cargado en el combo. Si es si lo muestra)
                                var $option = $("<option></option>", {
                                    "text": v.nombre,
                                    "value": v.idTipoUnidad

                                });

                            if (d == v) {
                                $option.attr("selected", "selected")
                                //$option = $("<option selected></option>", {
                                //    "text": v.nombre,
                                //    "value": v.idTipoUnidad
                                //});

                            }
                            $select.append($option);
                        }
                        });
                        return $select.prop("outerHTML");
                    }
                }

When I want to get the values of each row including the selects, it only shows the value (id) of the first select (it is not updated as I go through the table):

        var table = $('#tableItemsAuditorias').DataTable();
        var data = table.rows().data();
        //idTipoUM
        var x = table.rows();
        data.each(function (value, index) {
            alert('Data in index: ' + index + ' is: ' + value.nombre);
            alert('valor:  ' + $('.tipo-unidad').val()); //siempre muestra el mismo valor, el del primer select

        });

The row I'm going through when I read the select is not being updated ...

    
asked by Pablo 24.10.2018 в 03:47
source

0 answers