chaitu
chaitu

Reputation: 1216

How to implement pagination on datatables if server provides options for page_num in the api

I have an api/url that has query parameters for page_size and page_num. I am using ajax call to fetch data with hard-coded values for both and populating the table(working fine). But I want to populate datatable as user selects the page number. I can hard-code (ideally not) the page size, but i need dynamic ajax request to be made as user selects page number. How to implement this using datatables and jquery?

Upvotes: 0

Views: 134

Answers (1)

Shafiq Khan Blouch
Shafiq Khan Blouch

Reputation: 1

DECLARE @FirstRec int,@vQuery nvarchar(max) ,  
            @LastRec int  
            SELECT @FirstRec = (@pPageNo - 1) * @pPageSize -- Calculating the first rec no and last rec no  
            SELECT @LastRec = (@pPageNo * @pPageSize + 1) 

Select ROW_NUMBER() Over (Order By  Cast(AppointmentDate as Datetime) Desc) As RowNO, a.*
    Into #tbl
    From
    ( 
        select *
         from tbl
) a

    Select * From #tbl Where RowNo > @FirstRec AND RowNo < @LastRec 


Select COUNT(*) As TotalRecords From #tbl 

Upvotes: 0

Related Questions