1

I'm trying to use DataTable in client side mode. I mean I want to make all data loading, row adding and deleting processes done in client (web browser).

I'm using following code to initialize DataTable and it loads table rows correnctly from complex class object (PriceItems). But during in initialize process it makes http post request to server. Why? How can I prevent this?

var pricesTable = $('#pricesTable').DataTable({
     data: viewModel.product.PriceItems,
     columns: [{
         data: 'Id',
         visible: false
     }, {
         data: 'Name'
     }, {
         data: 'Value'
     }, {
         data: 'CurrencySymbol'
     }, {
         data: 'UnitName'
     }],

     sort: false,
     processing: false,
     serverSide: false,
     deferLoading: 0,
     info: false,
     filter: false,
     lengthChange: false,

     fnInitComplete: function (oSettings, json) {
         $('#pricesTable tbody tr:eq(0)').click();
     }

 });

EDIT-1: If I use (serverSide: true) DataTable stops calling mvc controller!
EDIT-2: Data model populated at server side with the following code.

var viewModel = new ProductFormViewModel(@Html.Raw(Json.Encode(Model)));
4
  • viewModel.product.PriceItems fetching the data ... Commented Nov 17, 2015 at 10:30
  • Please look at EDIT 2 Commented Nov 17, 2015 at 11:27
  • Has 'Model' actually been populated when you pass it to the view? Just wondering if your query uses deferred execution and is trying to enumerate the result set at the point of datatable initialisation. Commented Nov 17, 2015 at 11:42
  • Model populated in edit ([HttpGet]) action of controller and controller pass it to the view. Part of view is $(document).ready(function () { var viewModel = new ProductFormViewModel(@Html.Raw(Json.Encode(Model))); } Commented Nov 17, 2015 at 11:54

1 Answer 1

0

Removed data attribute from the initialization of datatable because it send request to that url, try following code .

var pricesTable = $('#pricesTable').DataTable({
     columns: [{
         data: 'Id',
         visible: false
     }, {
         data: 'Name'
     }, {
         data: 'Value'
     }, {
         data: 'CurrencySymbol'
     }, {
         data: 'UnitName'
     }],

     sort: false,
     processing: false,
     serverSide: false,
     deferLoading: 0,
     info: false,
     filter: false,
     lengthChange: false,

     fnInitComplete: function (oSettings, json) {
         $('#pricesTable tbody tr:eq(0)').click();
     }

 });
Sign up to request clarification or add additional context in comments.

7 Comments

How will the datatable be populated?
I've tried removing data attribute from initialization code but nothings changed. It persistently calling controller get action.
Then please check again that controller request initiated from where?
If I set serverSide property to true (in my case it should be false) datatable works as expected and never call any http post action method. But this time it calls to controller on adding rows at client :) Really interesting...
Unfortunately I have no solution yet
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.