How do I not repeat the value of an html cell

Asked

Viewed 100 times

0

How do I not repeat the value of a cell in an html table ?
For example I don’t want to repeat the cell value **DataPedido**

The query that will return me the data is this:

var _listaPedido = from _pedido in _pedidoAuxiliar
                                   join itens in _itemPedidoRepositorio.ListarItensPedido() on _pedido.PedidoID equals itens.PedidoID into subItemPedido
                                   from _itemPedido in subItemPedido.DefaultIfEmpty()
                                   join produtos in _produtoRepositorio.ListarProduto() on _itemPedido.ProdutoID equals produtos.ProdutoID into subProduto
                                   from _produto in subProduto.DefaultIfEmpty()
                                   join paes in _paoRepositorio.ListarPaes() on _produto.PaoID equals paes.PaoID into subPao
                                   from _pao in subPao.DefaultIfEmpty()
                                   join fermentacao in _fermentacaoRepositorio.ListarFermentacao() on _produto.FermentacaoID equals fermentacao.FermentacaoID
                                   orderby _pedido.DataPedido
                                   where _pedido.StatusPedidoID != 5
                                   group _itemPedido by new RelVendaQtdeProduto
                                   {
                                       PedidoID = _pedido.PedidoID,
                                       PaoID = _produto.PaoID,
                                       DataPedido = _pedido.DataPedido,
                                       NomePao = _pao.NomePao,
                                       NomeFermentacao = fermentacao.NomeFermentacao,
                                       QtdeTotal = _itemPedido.QtdItem
                                   } into grupoPedido

                                   select new RelVendaQtdeProduto
                                   {
                                       PedidoID = grupoPedido.Key.PedidoID,
                                       PaoID = grupoPedido.Key.PaoID,
                                       DataPedido = grupoPedido.Key.DataPedido,
                                       NomePao = grupoPedido.Key.NomePao,
                                       NomeFermentacao = grupoPedido.Key.NomeFermentacao,
                                       QtdeTotal = grupoPedido.Sum(i => i.QtdItem)
                                   };

Model

public class Modelo
    {
        public DateTime? DataPedido { get; set; }
        public string Pao { get; set; }
        public string Fermentacao { get; set; }
        public int QtdeTotal { get; set; }
        public decimal ValorTotal { get; set; }
        public IEnumerable<Modelo> Modelos { get; set; }
    }

Controller

public ActionResult Relatorio()
        {
            IEnumerable<Modelo> pedidos = new List<Modelo>{
                new Modelo{DataPedido=Convert.ToDateTime("2016-11-29 12:24:53.707"), Pao="PÃO CONGELADO"   , Fermentacao="F"               ,QtdeTotal=5   ,ValorTotal=decimal.Parse("105.00")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-11-29 12:24:53.707"), Pao="PÃO DE LEITE"    , Fermentacao="S/ Fermentação"  ,QtdeTotal=2   ,ValorTotal=decimal.Parse("16.20")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-11-29 12:24:53.707"), Pao="PÃO CONGELADO"   , Fermentacao="F"               ,QtdeTotal=15  ,ValorTotal=decimal.Parse("330.00")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-11-30 07:30:12.480"), Pao="PÃO COCO FRESCO" , Fermentacao="S/ Fermentação"  ,QtdeTotal=1   ,ValorTotal=decimal.Parse("10.50")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-11-30 07:30:12.480"), Pao="PÃO CONGELADO"   , Fermentacao="C"               ,QtdeTotal=8   ,ValorTotal=decimal.Parse("168.00")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-11-30 07:30:12.480"), Pao="PÃO CONGELADO"   , Fermentacao="L"               ,QtdeTotal=2   ,ValorTotal=decimal.Parse("42.00")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-12-01 06:39:53.477"), Pao="PÃO ASSADO"      , Fermentacao="S/ Fermentação"  ,QtdeTotal=175 ,ValorTotal=decimal.Parse("38.50")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-12-01 06:39:53.477"), Pao="PÃO DE LEITE"    , Fermentacao="S/ Fermentação"  ,QtdeTotal=2   ,ValorTotal=decimal.Parse("16.20")},
                new Modelo{DataPedido=Convert.ToDateTime("2016-12-01 06:39:53.477"), Pao="PÃO DE ASSADO"   , Fermentacao="S/ Fermentação"  ,QtdeTotal=35  ,ValorTotal=decimal.Parse("8.75")}
            };    
            var _pedido = pedidos.ToList();    
            return View(_pedido);
        }

View

<table>
            <thead>
                <tr>
                    <th class="aling-center">DATA PEDIDO&nbsp;</th>
                    <th>PAO&nbsp;</th>
                    <th>FERMENTAÇÃO&nbsp;</th>
                    <th>QTDE&nbsp;</th>
                    <th>VALOR&nbsp;</th>
                </tr>
            </thead>
            <tbody class="fonte10">
                @{
                    foreach (var item in Model)
                    {
                        <tr>
                            <td>@item.DataPedido&nbsp;</td>                            
                            <td>@item.Pao&nbsp;</td>
                            <td>@item.Fermentacao&nbsp;</td>
                            <td>@item.QtdeTotal&nbsp;</td>
                            <td>@item.ValorTotal&nbsp;</td>
                        </tr>
                    }
                }

            </tbody>
            <tfoot>
                <tr>
                    <td colspan="10" class="bold"></td>
                    <td class="aling-right"></td>
                </tr>
            </tfoot>
        </table>

inserir a descrição da imagem aqui

  • Is this report fixed this way? If not, you need to put exactly how this information is generated, or, if you want to do this treatment via js you also have to specify. How do you want to treat this exactly?

  • It is not fixed not put this way as an example, there is a screen of FILTER where the user will enter a date period INITIAL and FINAL.

  • that is, you make a bank consultation?

  • You want to treat in consultation or in the final result of html?

  • Another question, what language is this?

  • The query is made in BD Sql Server and if possible treat in the query I think better and the language is MVC.

  • MVC is not a language, it’s an architecture standard, what you’re using is C3, .NET..? I don’t know much about these languages.

  • Anyway, I guarantee that if you want to treat in the query you need to post as you are doing, and not a fixed example...

  • Yes Csharp dot.net

  • Okay, so post the code that makes the query!

  • I put the fixed data to make it easier to understand, anyway I updated the question by adding the query, if it is complicated can give the solution via html as well.

  • The solution via javascript is simple, but the ideal is you treat in consultation even...I’m doing some research...

Show 7 more comments

2 answers

0

In the loop display, you can feed a array and check if the value has already been displayed before:

@{
    List<String> used = new List<String>;

    foreach (var item in Model)
    {
        @if(Array.IndexOf(used, item.DataPedido) < 0) {
            <tr>
                <td>@item.DataPedido&nbsp;</td>                            
                <td>@item.Pao&nbsp;</td>
                <td>@item.Fermentacao&nbsp;</td>
                <td>@item.QtdeTotal&nbsp;</td>
                <td>@item.ValorTotal&nbsp;</td>
            </tr>
        }

        @used.add(item.DataPedido);
    }
}

0

Since this is a need of the interface ("How do I not repeat the value of a cell in an html table?") then neither the Model class nor the Controller class should be modified to meet this need, preferably only the View class.

Use the attribute rowspan=quantidade de linhas tag td initially computing the number of lines to "jump" in a previous loop. For better maintainability, create a specific View class that commits this amount of lines and generates the corresponding HTML code.

Browser other questions tagged

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