سؤال

The followings is the code for paginated datatable in my JSP:

$(document).ready( function() {
    $('#paginatedTable').dataTable( {
        "bServerSide" :true,
        "sAjaxSource" :"/JQueryPagination/Myservlet",
        "bProcessing" :false,
        "sPaginationType" :"full_numbers",
        "bJQueryUI" :false,
        "aoColumns" : [ {
            "mDataProp" :"Name"
        }, {
            "mDataProp" :"Address"
        }, {
            "mDataProp" :"Town"
        } ]
    });
});

In my servlet, I have a query that fetches the entire data from a database table, say company which returns me a million rows in the result set.

List<Company> companies =  fetchCompleteCompanyDataFromDb(); 

This result set is then filtered as below:

List<Company>filteredCompanyList = companies.subList(iDisplayStart,DisplayStart+iDisplayLength);

The filteredCompanyList is the list I'm displaying in the datatable, which is 10 rows. When the user clicks the 'Next' button of the pagination, a new request is fired with will fetch the complete company data again and then the next 10 records for the second page is filtered. In short, whenever the user clicks the next button, a query for fetch a million record is fired.

I need to know whether is there a way where when the user clicks the next button, only the next 10 records to show will be fetched.

هل كانت مفيدة؟

المحلول 2

The solution for this most likely lies in how fetchCompleteCompanyDataFromDb() is implemented. Depending on how you're doing this, you may want to implement a new function:

fetchPageFromDb(int pageNumber, int pageSize)

It is hard to suggest any particular implementation since I have no idea how fetchCompleteCompanyDataFromDb() works so I'm assuming your pagination needs to be implemented as part of the code that forms your query. Google up on how to implement paging in SQL and report back on what you've learned.

نصائح أخرى

Thanks for your inputs..I was able to fix the issue. my requirement was to fetch only 10 records at a time. When the user clicks the next page, a new request should be fired that will fetch the next 10 rows to display. In this manner, I can implement pagination with better performance. If found that, there are two variables, that control the pagination. They are 'iTotalRecords' & 'iTotalDisplayRecords'. I will query the table to get the count of the entire rows in the table & set it to 'iTotalRecords'. Then I make an assignment of 'iTotalDisplayRecords = iTotalRecords'.This way I will falsely inform the plugin that I have the entire list of rows with me. But with the help of variables 'iDisplayStart' & 'iDisplayLength', I will only fetch the required number of rows from the db & write back to the response as a json. Thanks to all again.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top