Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
data sorting via primary key in jquery data table

I have displayed data in view page using data table. I want to display data in descending order according to

public ActionResult Index()
        {
            return View(db.BusinessRegModel.OrderByDescending(v => v.BusinessId).ToList());

        }

BusinessId is primary key.

But in view page, data is not sorted via primary key. I am using jquery data table to display data.

<table id="tblBusinessData" class="table" width="100%" cellspacing="0">
    <thead>
        <tr>
            <th>Edit/Print</th>
            <th>
                @Html.DisplayNameFor(model => model.RegNum)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.RegDate)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.NameOfFirm)
            </th>
            //code blocks
             </tr>
    </thead>
     <tbody>
        @foreach (var item in Model)
        {
        <tr>
            <td width="20%">
                @Html.ActionLink("Edit", "Edit", new { id = item.BusinessId }, new { @class = "btn btn-warning" })
                @Html.ActionLink("Print", "Details", new { id = item.BusinessId }, new { @class = "btn btn-danger" })
            </td>
            //code blocks
        

But the data is not sorted in descending order via BusinessId key. How can I do this? I need to display data in descending order by BusinessId.

jquery code

<script type="text/javascript">
            $('#tblBusinessData').DataTable();
    </script>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Add the column Id to the HTML and hide it via configuration:

$('#tblBusinessData').DataTable({
  "columnDefs": [{
    "targets": [0],
    "visible": false
  }],
  "order": [
    [0, "desc"]
  ]
});
about 4 years ago · Juan Pablo Isaza Relatório

0

If you are able to set the desired order in your data before you send it to DataTables, you can simply set order: [] to disable the initial sort while still being able to click on the column headers.

$('#tblBusinessData').DataTable({
    order: []
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda