How to add a row dynamically when using server-side processing?

How to add a row dynamically when using server-side processing?

integral_devintegral_dev Posts: 5Questions: 0Answers: 0
edited September 2011 in General
Hi, I am using datatables with server-side processing turned on.

There are instances where persistence in database is done asynchronously, but I do get the event on server when something will be added and need to show that on the client. In that case, I want to add a row on client and increment the count.

The way I implemented is by following these steps:
1. set bserverside to false
2. call fnAddData()
3. set bserverside to true

This way row gets added on the client but since client only had current page - the total number of records become (page size + 1) instead of (previous total count + 1). I tried changing settings._iRecordsTotal but it doesnt help.

Can you please help or provide me with any other approach? Thanks so much!!

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    With server-side processing, client-side data storage functions such as fnAddData aren't really going to help, since DataTables knows nothing about your server-side environment. The data store is on the server, so whenever you want to modify that data, you need to do it on the server, and then simply call fnDraw() to have DataTables refresh the dataset from the server.

    Allan
  • integral_devintegral_dev Posts: 5Questions: 0Answers: 0
    Allan - I appreciate your prompt response.

    For my problem, I was looking for a solution where I want to do pagination and sorting by server. Only in case of live updates I need to add rows dynamically to datatable - since data gets stored in table asynchronously on the server - the pagination view will be consistent. The only issue is that server generates an event when something needs to be added - not when its finally persisted.

    Can you provide any alternate mechanism to do that? Thanks again.
  • integral_devintegral_dev Posts: 5Questions: 0Answers: 0
    I need some solution soon - I think if you could please tell me how to change total number of records on client side datatable and then I will fnDraw() that will solve my issue. Please let me know.
  • integral_devintegral_dev Posts: 5Questions: 0Answers: 0
    Hi Allan,

    I am now able to set total count when using client side pagination.
    settings.aiDisplayMaster.length = totalCount + 1;

    I am using table.fnDraw() but for some reason it is breaking. Can you please point me to the correct API which can redraw the table when its client side implementation.
This discussion has been closed.