views:

36

answers:

2

This my jquery function,

function getRecordspage(curPage, pagSize) {
   // code here
$(".pager").pagination(strarr[1], { callback: 
         function() { getRecordspage(2, 5);},current_page: curPage - 1, 
          items_per_page:'5',  num_display_entries: '5', next_text: 'Next', 
           prev_text: 'Prev', num_edge_entries: '1'
      });

}

and i call this jquery function,

<script type="text/javascript">
         $(document).ready(function() {
             getRecordspage(1, 5);
         });

</script>

As you see my It works fine for 1st time and my callback function is configured to the current function itself... when it gets called the callback gets executed over and over again.... How can i prevent this? Any suggestion....

EDIT:

This is my function

function getRecordspage(curPage, pagSize) {
    $.ajax({
        type: "POST",
        url: "Default.aspx/GetRecords",
        data: "{'currentPage':" + curPage + ",'pagesize':" + pagSize + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(jsonObj) {
            var strarr = jsonObj.d.split('##');
            var jsob = jQuery.parseJSON(strarr[0]);
            var divs = '';
            $.each(jsob.Table, function(i, employee) {
                divs += '<div class="resultsdiv"><br /><span class="resultName">' + employee.Emp_Name + '</span><span class="resultfields" style="padding-left:100px;">Category&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.Desig_Name + '</span><br /><br /><span id="SalaryBasis" class="resultfields">Salary Basis&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.SalaryBasis + '</span><span class="resultfields" style="padding-left:25px;">Salary&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.FixedSalary + '</span><span style="font-size:110%;font-weight:bolder;padding-left:25px;">Address&nbsp;:</span>&nbsp;<span class="resultfieldvalues">' + employee.Address + '</span></div>';
            });
            $("#ResultsDiv").append(divs);
         }
    });
}
+2  A: 

The callback function in this case is to display the appropriate content, not do the pagination, your setup should look more like this:

var itemsPerPage = 5;
$(document).ready(function() {
  $(".pager").pagination(maxNumberOfElementsHere, { 
     callback: getRecordspage,
     items_per_page: itemsPerPage,
     num_display_entries: 5,
     next_text: 'Next', 
     prev_text: 'Prev',
     num_edge_entries: 1
  });
});

function getRecordspage(curPage) {
 // itemsPerPage is the new pagSize you have now
 // code here
}
Nick Craver
@Nick as you said do i have to pass value for `curPage` on page click
Pandiya Chendur
@Pandiya - The plugin already passes currentPage and the panel as arguments to your callback function.
Nick Craver
@Nick `strarr[1]` and `curPage` value is null since i get this value inside `getRecordspage` function...
Pandiya Chendur
@Pandiya - That argument is number of elements to paginate, why would it change? Edited to make both of these a bit clearer
Nick Craver
@Nick i got you but what i say is the value for `maxNumberOfElementsHere` will come from my function is shown in my edit...
Pandiya Chendur
@Nick `strarr[1]` has a value `17` which has to be passed to `maxNumberOfElementsHere`
Pandiya Chendur
@Pandiya - You should move the code which determines the max number of elements into the document.ready part, this won't change and needs to be set from the start.
Nick Craver
@nick look at my method i am getting json data from my aspx page and splitting it.... My first array contains json data and my second contains value for `maxNumberOfElementsHere `
Pandiya Chendur
@nick that worked....
Pandiya Chendur
@nick current page param does trouble me a lot...
Pandiya Chendur
@Pandiya - how so?
Nick Craver
A: 

The fact that you are calling the function in the function is causing the problem. It's causing an infinite loop, and will never end.

You need to give it an IF statement so it will end at some point.

Scott Hovestadt
@scott can you suggest me how it can be done..
Pandiya Chendur