I have a dynamic table that I paint by means of Javascript, only that I have a problem when selecting the client in the DropDownList, it shows me the table, and if I change the client I insert the lines in the same table, I would like it to select another client the table will be cleaned and I will only insert the lines of the selected client !!!
SelectedClient: function () {
InventarioE.ClienteId = $("#ClienteId").val();
InventarioE.FechaInventario = $("#FechaTxt").val();
Inventario.getInventario();
},
//Obtiene la información para la tabla de inventarios
getInventario: function () {
General.ajax({
url: InventarioE.uriInventario,
data: {
ClienteId: InventarioE.ClienteId, Fecha: InventarioE.FechaInventario, Proceso: InventarioE.proceso
},
type: Method.Post,
Callback: Inventario.CallBackGetListaInventarios
});
},
CallBackGetListaInventarios: function (data) {
var dta = data.aaData.Model;
Loading.ShowLoader();
InventarioE.tblInventarioId.destroy();
if (dta != null)
dta.forEach(Inventario.InsertaRenglon)
InventarioE.tblInventarioId = $('#tbInventarioId').DataTable(
{
language: Grid.languageDefault,
dom: 'ft<"lengt"l><"info"i><"pagination"p>',
});
Loading.HideLoader();
console.log(data);
},
//Metodo para dibujar tabla
InsertaRenglon: function (item, index, arr) {
var table = document.getElementById("tblInventarioId");
var row = table.tBodies[0].insertRow();
row.id = "tc" + item.NumeroDeParte;
var cell0 = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
var cell3 = row.insertCell(3);
var cell4 = row.insertCell(4);
cell0.innerHTML = item.Descripcion;
cell1.innerHTML = item.NumeroDeParte;
cell2.innerHTML = item.AlmacenId;
cell3.innerHTML = item.AlmacenDesc;
cell4.innerHTML = "<input type='text' class = 'form-control input-sm jsTrim jsNumber' name='type' id='txt" +
item.NumeroDeParte + item.AlmacenId + "' value='" + item.Cantidad + "'style='width:50px '>";