I am creating the runtime table in mvc3.net. From controller i am getting the json collection and in view am creating the runtime table according to json collection
first am just initialising the table
<div id="DisplayBookChapterList" class="fLeft per30 mr15">
<table class="contentTable" id="tblDisplayChapterList" >
</table>
In Runtime am populating the table rows by below given code
$.getJSON("@Url.Action("GetBookChapterList", "CourseManagement")" + '/' + bookname, function (data) {
$.each(data, function (key, val) {
BookChapterlist += '<tr><td style="display:none" id=ChapterListBookID value=' + val.BookID + '>' + val.BookID + '</td><td>' + val.ChapterNo + ' </td><td>' + val.Title + '</td><td><input type=checkbox id="' + val.ChapterID + '"></td></tr>';
}
});
$('#DisplayBookChapterList table').append(BookChapterlist);
I want to give paging to this dynamically created table.
You’ll want to create the paging links to select a specific page, next, previous, first, last or whatever you need. E.g.
Note that all links have the css class “page-link”.
On the server side, add a “page” parameter to your action so you know which page to fetch in the controller.
Now, back to the HTML code: the href of each link is the address where to fetch the data from and we can use this in our JavaScript code:
The nice thing about this approach is that you can make it easily fall back for clients that have JavaScript disabled: in the “GetBookChapterList” action, check if the request is an ajax request (Request.IsAjaxRequest()). If so, return the required JSON data. If not, render a normal, full page showing the selected page of the table.
This is generally a good approach: if possible, make sure the site works without JavaScript, then add JavaScript to improve it.