Exact difference in between Ajaxsource and Serverside & issue with MVC view model

Exact difference in between Ajaxsource and Serverside & issue with MVC view model

kahlil312kahlil312 Posts: 16Questions: 0Answers: 0
edited June 2013 in DataTables 1.9
hi



I was wondering on the actual difference (in implementation terms) between Ajax source and Server side processing.
Every single one of the many examples for Datatables that use Ajax as source i.e. ("sAjaxSource"=getDataURL), also use "bServerSide"=true?

Does this mean if you are getting the data from the server via Ajax using sAjaxSource call to a database, the Server HAS to provide all the implementation for paging sorting etc etc?
This therefore means Ajax source w/out server call is purely to access simple data in Datatable array format from a text file (for e.g.)?

Possibly I have something mixed up here - the reason for asking the above is that I need to populate a datatable from a ASP.NET MVC4 View Model using simple HTML rendered directly from Controller, and would like to retain the client side functionality for sorting etc as its 'already there' :). i.e. the 'push' rather than 'pull' model.

In addition I need Editor plugin CRUD functionality on the grid along with a postback to the Controller for POST processing.
I have looked at a large number of examples for this functionality and all of them implement server side methods for datatable processing and Ajax calls e.g. http://www.codeproject.com/Articles/155422/, which is fine I guess if you have lots of records to process which i don't.

I am using the following link as a reference for the View model binding to Editor area:
http://datatables.net/forums/discussion/10877/mvc3-using-datatable-and-editor
This works well (upto a point) - there are issues with how the Editor plugin field mappings "reads" the rendered HTML hence the selected row values do not appear in the popup when editing a row.

Details:
The HTML rendered by the MVC view is as follows : (using MVC EditorFor)
[code]

Replies

  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    Hi,

    > Every single one of the many examples for Datatables that use Ajax as source i.e. ("sAjaxSource"=getDataURL), also use "bServerSide"=true?

    That's not correct. All of the examples under the "Ajax data source" example list here use client-side processing with Ajax fetched data: http://datatables.net/examples/ . For example: http://datatables.net/release-datatables/examples/ajax/objects.html .

    > This therefore means Ajax source w/out server call is purely to access simple data in Datatable array format from a text file (for e.g.)?

    Sort of. You can get it from a text file, php, C# anything you want. Also it does' thane to be in array format, you can use objects. DataTables can consume almost any JSON data format.

    Fundamentally the difference is that in client-side processing, the client-side has the whole data set, while on server-side processing only the server has the full data set. Server-side processing would be used when you are working with very large tables, so you can utilise the database - since that is what they are designed for!

    > [Editor] have looked at a large number of examples for this functionality and all of them implement server side methods for datatable processing and Ajax calls

    Actually, only one of the examples here ( http://editor.datatables.net/examples/ ) implemented server-side processing. All of the others implement client-side processing.

    Do this answers resolve your other questions?

    Allan
  • kahlil312kahlil312 Posts: 16Questions: 0Answers: 0
    Sorry Allan, when I mentioned having looked at a large number of examples I should have clarified that I looked outside datatables.net web sites, because all examples here seem to be on php and I am working with ASP.NET.

    A great many of the ASP.NET examples use ServerSide logic hence my comment on paucity of resources..
    However you have clarified that I can return an object via sAjaxSource and have it processed client side so this should work in theory using MVC Viewmodel.
    I've in fact attempted this approach and seem to be successfully returning an object using this method.
    Are there any tips you can share in terms of formatting the JSON returned to allow DT to read this easily or even if you can point me to some documentation on this site. Some tips on rendering JSON for dropdownlists/check boxes would be invaluable.

    Re my other questions - they are all to do with my earlier client side DOM source HTML table set up and whether this can be used with Editor plugin to perform CRUD...I'd like your opinion on this whenever you have some time to look at it as I am still interested in using this approach if I can get the binding to work.

    Thanks again.
  • allanallan Posts: 63,204Questions: 1Answers: 10,415 Site admin
    > Are there any tips you can share in terms of formatting the JSON returned to allow DT to read this easily

    Have an array, where each item in that array is a row in the table. That's about the only fundamental requirement for DataTables. Beyond that you can use sAjaxDataProp and mData to extract any data you want from the data source.

    This blog post will also likely be of interest: http://datatables.net/blog/Extended_data_source_options_with_DataTables .

    > Some tips on rendering JSON for dropdownlists/check boxes would be invaluable.

    If you want select elements etc in the table, I'd suggest using the mRender function to generate the HTML needed (a companion function to mData ).

    Regarding the rest - are you able to link me to a page showing the problems? It sounds like you are using the HTML form elements created by the server rather than Editor. Is that correct, or am I misreading? That's unexpected, and not really supported by Editor at this time (it probably will be in a future version though). I'm not sure how it is tying in at the moment.

    Thanks,
    Allan
This discussion has been closed.