Cómo puedo cargar informacion en un datatable a partir de lo que seleccione en un Select

Cómo puedo cargar informacion en un datatable a partir de lo que seleccione en un Select

joan0627joan0627 Posts: 5Questions: 3Answers: 0
edited November 2020 in Free community support

Tengo lo siguiente:

  var listar = function(){
       
     

    var proveedor = $("#proveedor").val();

   var table= $("#example1").DataTable({
      
        destroy: true,
        "ajax":{
        type: "POST",
        url: "/tienda/Compra/proveedormarca/",
        data: {
            
            proveedor:proveedor
        
        },

    },
    language: {
        searchPlaceholder: "Estoy buscando...",
        url: "../assets/plugins/datatables/Spanish.lang",
    },
    bInfo: false,
    lengthMenu: [
        [5, 15, 25, 50, 100, -1],
        [5, 15, 25, 50, 100, "Todo"],
    ],


     columns : [
         {"data":"idProducto"},
        {"data":"idCategoria",
        "visible": false,
         },

         {"render":
         function ( data, type, row ) {
           return (row.descripcionPresentacion + ' X ' + row.valorMedida + ' '+row.descripcionUnidadmedida + ' '+row.nombreProducto);
             }
         },

         {
            
            defaultContent:
                "<div class='input-group' style='width: 80%;'><input  type='text' value='1' class=' form-control cantidadinput'></div>",
        },
        {
      
            defaultContent:
                " <div class='input-group '><div class='input-group-addon' style='color:green; font-weight: bold; font-size:20px'>$</div><input  data-inputmask=''alias': 'currency', 'prefix':'','radixPoint':',', 'groupSeparator': '.', 'autoGroup': 'true',  'digits': 0,'digitsOptional': 'false','min': 0,'max': 100,'allowMinus': 'false','autoUnmask': 'true','placeholder': '0', 'clearMaskOnLostFocus': 'false', ' name='costoinput' type='text' class='costoinput form-control 'style='text-align:right' ></div>",
        },
        {
       
            defaultContent:
                " <div class='input-group '><input  max=99 type='text' class=' percent form-control ivainput 'style='width:85% ;' value='0' ><div class='input-group-addon' style='color:gray; font-weight: bold; font-size:20px'>%</div></div>",
        },
        {
           
            defaultContent:
                "<button class='btncarrito' style=' border: none; background: none; outline: none;'><i class='fas fa-cart-plus' style='font-size:28px;color: #5CB85C; '></i></button>",
        },

        
         ]

         
        


        });


    }

No me funciona bien ya que necesito que los datos permanezcan en el modal(tengo el datatable en el modal) pero se me destruyen pq puse la funcion destroy(); y si no la pongo me sale error.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.