Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda