Fill screen with data from an auxiliary table

Asked

Viewed 26 times

0

I created a Service Order registration, the insertion is working perfectly, I’m trying to create the change page, this screen brings all the data, I just can’t list the items in the table.

Follows the codes.

CONTROLLER:
        public JsonResult PreencheOrdemServicoDetalheServico(string _codigo)
        {
            OrdemServicoDetalheServico ObjOrdemServicoDetalheServico = new OrdemServicoDetalheServico();
            ObjOrdemServicoDetalheServico.IdOrdemServico = _codigo;

        List<OrdemServicoDetalheServico> OrdemServicoDetalheServico = objOrdemServicoDetalheServicoNeg.findAllPorOS(_codigo);



        return Json(new { OrdemServicoDetalheServico }, JsonRequestBehavior.AllowGet);
    }

FUNCTION: (I CREATED THE FUNCTION BECAUSE I COULD NOT BRING THE ITEM DATA WHEN LOADING THE PAGE)

 function PreencheOrdemServicoDetalheServico() {
        $.ajax({
            url: '/OrdemServico/PreencheOrdemServicoDetalheServico',
            data: { _codigo: $("#idOS").val() },
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            type: "GET",
            success: function (data) {

            var result = data.Result;

            $(result).each(function (i) {

                cadeia = "<tr>"
                cadeia = cadeia + "<td>" + result[i].IdServico + "</td>";
                cadeia = cadeia + "<td>" + result[i].Descricao + "</td>";
                cadeia = cadeia + "<td>" + result[i].QuantidadeServico + "</td>";
                cadeia = cadeia + "<td>" + result[i].ValorUnitarioServico + "</td>";


                var y = 0;
                var x = 0;
                var des = 0;
                y = result[i].QuantidadeServico//$("#quantidade").val();
                x = result[i].ValorUnitarioServico//$("#preco").val();
                subtotal = (x * y); // - des;
                cadeia = cadeia + "<td>" + subtotal + "</td>"
                cadeia = cadeia + "<td><a class ='elimina'><button class='btn btn-danger' type='button'><span class='fa fa-remove'></span></button></a></td>";
                $("#detalhe tbody").append(cadeia);
                somar();
                fn_dar_eliminar();
                limpar();

            });

        },
        error: function (error) {
            alert("Erro na chamada da função Preenche Serviços");
        }
    });
}

TABLE (TABLE) LIST OF SERVICE ITEMS.

<table id="detalhe" class="lista table" border="1">
     <thead style="font-size:12px;">
          <tr class="bg-success">
              <th>Código</th>
              <th>Serviço</th>
              <th>Quantidade</th>
              <th>Preço</th>
              <th>Total</th>
              <th>&nbsp;</th>
          </tr>
     </thead>
<tbody></tbody>

</table>
  • I didn’t understand if you wanted to list the items only with Razor and without JS or want to build the listing with JS.

  • Then I have an Ordemservico table and a table of Services items, I need to list the services that was registered for this order on the edit screen.

  • Error in the use of the method .each(), because it should be result.each(function (i) {...} and you have to add the elements to the cadeia with cadeia += .... By using the = you’re replacing the previous.

  • Thank you very much for your attention, but from what I realized is that it is not possible to call two functions then, because when I call separately it works. I don’t know how to wait for the first function to close to call the other.

  • <head> <script type="text/javascript"> window.onload = Function() { Fills client(); Fills mservicodeServico(); Fills(); } </script> </head>

  • What do you mean? What’s the point and what’s going wrong?

  • As I mentioned above I have the Fillcustomer function, If I put all three together, the error occurs informing that the connection is open, if I do one by one, there is no error. I tried to put one in window.onload and another in (Document). ready even then the error happens. I don’t know what else to do. need to load all functions when opening the screen. Again thank you for your attention to my problem.

  • So your initial question has nothing to do with the problem you describe. Share the code of these three functions.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.