Hi
How to do Paging in Jquery DataTable. In the below Method it will display all records from the Database.
Suppose there are 14 records & 5 records per page setting. I want that is should bring 1-5 records . If user clicks on 3 them 11-14 records should be displayed.
- public ActionResult Index()
- {
- return View();
- }
- @model IEnumerable<MyApplication.Models.Location>
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>Index</title>
- </head>
- <body>
- <p>
- </p>
- <table class="table" id="tblLocation">
- <tr>
- <th>
- @Html.DisplayNameFor(model => model.Description)
- </th>
- <th></th>
- </tr>
- @foreach (var item in Model)
- {
- <tr>
- <td>
- @Html.DisplayFor(modelItem => item.Description)
- </td>
- <td></td>
- </tr>
- }
- </table>
- </body>
- </html>
- <script src="~/Scripts/Appjs/Location.js"></script>
-
- ********************************************
- $(document).ready(function () {
-
- $("#tblLocation").dataTable({
- ajax: {
- type: "get",
- url: "/Location/List",
- dataType: "json",
- dataSrc: ""
- },
- columns: [
- {
- data: "Id",
- visible: false
- },
- {
- data: "Description"
- },
- {
- data: "LocationId",
- render: function (data) {
- return "<button class='btnEdit btn btn-primary'data-LocationId=" + data + ">Edit</button>";
- }
- },
- {
- data: "PostId",
- render: function (data) {
- return "<button class='btnDelete btn btn-danger' data-LocationId=" + data + ">Delete</button>";
- }
- }
- ]
- });
- });
Thanks