none
Ordenar sem DataTable RRS feed

  • Discussão Geral

  • Boa tarde pessoal.

    Estou com uma situação, trabalho com Visual Basic 2015, MVC, C# e html.
    Em uma tabela para um cliente preciso alterar dinamicamente ao clicar no campo da coluna (Nome, Data, etc...) de Crescente para Decrescente. Segue um pedaço do código.

    Na View

            {
                <input type="hidden" id="ordenacao" name="ordenacao" value="">
                <div class="portlet-body">
                    <div class="table-scrollable">
                        <table class="table table-hover" id="data">
                            <tr>
                                <th class="titulo_detalhe" style="width: 70px"><b><a href='javascript:Ordenacao("Identificação")'>Identificação</a></b></th>
                                <th class="titulo_detalhe" style="width: 40px"><b><a href='javascript:Ordenacao("Data")'>Data</a></b></th>
                                <th class="titulo_detalhe" style="width: 20px"><b><a href='javascript:Ordenacao("Nome")'>Nome</a></b></th>
                                <th class="titulo_detalhe" style="width: 50px"><b><a href='javascript:Ordenacao("Assunto")'>Assunto</a></b></th>
                                <th class="titulo_detalhe" style="width: 20px"><b><a href='javascript:Ordenacao("CPF")'>CPF</a></b></th>
                                <th class="titulo_detalhe" style="width: 20px"><b><a href='javascript:Ordenacao("Solicitação")'>Solicitação</a></b></th>
                                <th class="titulo_detalhe" style="width: 50px"><b><a href='javascript:Ordenacao("Status")'>Status</a></b></th>
                                <th class="titulo_detalhe text-center" style="width: 100px"><b><a href='javascript:Ordenacao("Resposta")'>Resposta</a></b></th>
                            </tr>
                            @foreach (var questao in Model)
                            {
                                <tr>
                                    @if (questao.Resposta == null)
                                    {
                                        <td class="detalhe">
                                            <a href='Detalhe?identificacao=@questao.Identificacao'>
                                                @questao.Identificacao
                                            </a>
                                        </td>
                                    }
                                    else
                                    {
                                        <td class="detalhe">
                                            <a href='QuestaoRespondida?identificacao=@questao.Identificacao'>
                                                @questao.Identificacao
                                            </a>
                                        </td>
                                    }
                                    <td class="detalhe">
                                        @questao.Data.ToString("dd/MM/yyyy")
                                    </td>
                                    @if (questao.Solicitacao != "DENÚNCIA ANÔNIMA")
                                    {
                                        <td class="detalhe">
                                            @questao.Nome
                                        </td>
                                    }
                                    else
                                    {
                                        <td class="detalhe">
                                            &nbsp;
                                        </td>
                                    }
                                    <td class="detalhe">
                                        @questao.Assunto
                                    </td>
                                    @if (questao.Solicitacao != "DENÚNCIA ANÔNIMA")
                                    {
                                        <td class="detalhe">
                                            @questao.CPF
                                        </td>
                                    }
                                    else
                                    {
                                        <td class="detalhe">
                                            &nbsp;
                                        </td>
                                    }
                                    <td class="detalhe">
                                        @questao.Solicitacao
                                    </td>
                                    @if (questao.Indeferido == false)
                                    {
                                        <td class="detalhe">
                                            @(questao.Resposta == null ? "Em Atendimento" : "Atendido")
                                        </td>
                                        <td class="detalhe text-center">
                                            @(questao.Resposta == null ? "-------" : questao.Resposta)
                                        </td>
                                    }
                                    else
                                    {
                                        <td class="detalhe">
                                            @(questao.Indeferido == false ? "Lido" : "Rejeitado")
                                        </td>
                                        <td class="detalhe text-center">
                                            @(questao.Indeferido == null ? "-------" : "Indeferido")
                                        </td>
                                    }
                                </tr>
                            }
                        </table>
                    </div>
                </div>
            }

    @section scripts{
        <script type="text/javascript">
            function Ordenacao(campo) {
                $("#ordenacao").val(campo);
                $("#form1").submit();
            }
        </script>
    }
    Controller

     public ActionResult Lista(int? exercicio, string ordenacao)
            {
                int _exercicio = (exercicio == null ? DateTime.Today.Year : Convert.ToInt32(exercicio));
                var dados = new Dados(_exercicio);
                var lista = dados.Questionamentos.Questoes;
                if (ordenacao == "Identificação") lista = lista.OrderBy(x => x.Identificacao).ToList();
                if (ordenacao == "Data") lista = lista.OrderBy(x => x.Data).ToList();
                if (ordenacao == "Nome") lista = lista.OrderBy(x => x.Nome).ToList();
                if (ordenacao == "Assunto") lista = lista.OrderBy(x => x.Assunto).ToList();
                if (ordenacao == "CPF") lista = lista.OrderBy(x => x.CPF).ToList();
                if (ordenacao == "Solicitação") lista = lista.OrderBy(x => x.Solicitacao).ToList();
                if (ordenacao == "Status") lista = lista.OrderBy(x => x.Indeferido).ToList();
                if (ordenacao == "Resposta") lista = lista.OrderBy(x => x.Resposta).ToList();
                return View(lista);
            }

    quarta-feira, 29 de novembro de 2017 17:48

Todas as Respostas