Sushant Torankar

Sushant Torankar

  • 2.1k
  • 92
  • 2.8k

About Datatable sorting

Apr 19 2022 7:32 AM

Hello,

I am using Datatable in my MVC project, It works well

 $(document).ready(function () {
                $('#Table_name').dataTable();
            });

But in sql query, I got all records in desc order, but when it binds to datatable, it does not bind in desc order.I think it binds in alphabetical order

select * from table_name order by CreatedDate desc

If if I remove .dataTable(), it will bind in desc order, but then my table won't have search filter, pagination...etc

I want both datatble and order by CreatedDate desc in sql query

How to use datatable in such case?

Thank you


Answers (2)