How to scroll to first row during pagination in Jquery Datatables.

How to scroll to first row during pagination in Jquery Datatables.

nehagnehag Posts: 1Questions: 1Answers: 0
edited May 2017 in Free community support

Hello Friends,

I am new to DataTables and i am using it in order to display the contents which i am getting from the database.
i am not able to scroll to the top of the page or to the first row when i click on pagination buttons from the bottom of the page.
Below is the code: -

$.ajax({
      contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
      type: "GET",
      url: "xyz",
      data: dataString,
      async: "false",
      datatype: "json",


      success: function(response) {

           writeResultTable();
           var obj = parseJSONfromSearch(response);

           $('#tableId').DataTable( {
                data: obj,
                "bJQueryUI": true,
                "bPaginate" : true,
            "sPaginationType" : "simple",
            "bServerSide": false,
            "fixedHeader": true,
                columns : [
                           { "targets": [0],
                               "sortable" : true,
                                "render":function(data, type, full, meta){
                                   return '<a href="'+full.url+'" target="_blank">' + full.TitlePath + '</a>' + "<br\>" + "<br\>" +                                                                                                                                                                                  full.Description;

                                }}

                       ],
                       "sDom" : '<"top"l<"divline"ip>>rt<"bottom"<"divline"ip>><"clear">',
                "sAutoWidth" : true,
                 "fnDrawCallback": function(o) {

                        moveToTop(); 


                  }  
            } );

      },

      error: function(response, status, error ) { 
          alert("error123");
          alert(status);
          alert(error);

      }
    });

function moveToTop(){
window.scrollTo(0, 0);

// document.body.scrollTop = 0;
// document.documentElement.scrollTop = 0;

}

I tried several things like below but nothing works: -

function paginateScroll() {
$('html, body').animate({
scrollTop: $(".dataTables_wrapper").offset().top
}, 500);
console.log('pagination button clicked');
$(".ui-button").unbind('click', paginateScroll);
$(".ui-button").bind('click', paginateScroll);
}
paginateScroll();

Please help me out with this.
Thanks

This discussion has been closed.