0

I am using jquery DataTable 1.9 and facing a weird problem.My code is sending many(equal to the column in a table) requests to the server.Below is the code , I am using :

  tableContainer.dataTable({

            sDom: '<"row"<"span6"l><"span6">r>t<"row"<"span6"i><"span6"p>>',
            sPaginationType: 'bootstrap',
            bProcessing: true,
            bServerSide: true,
            bStateSave: false,
            bPaginate: true, 
            oLanguage: {
                sLengthMenu: '_MENU_ records per page'
            },
            bFilter: true,
            bSort: false ,
            // Setup for responsive datatables helper.
            bAutoWidth: false,
            fnPreDrawCallback: function ()
            {
                // Initialize the responsive datatables helper once.
                if (!responsiveHelper)
                {
                    responsiveHelper = new ResponsiveDatatablesHelper(tableContainer, breakpointDefinition);
                }

            },

            fnRowCallback: function (nRow, aData, iDisplayIndex, iDisplayIndexFull)
            {
                responsiveHelper.createExpandIcon(nRow);
            },

            bDestroy: true,
            sAjaxSource: "Getdata",
            bDeferRender: true,
            aoColumns: [

                @foreach (var item in Model.gridAllColumnName)
                {
                    <text> { "sName": "@item" }, </text>
                }

            ]
               ,

            fnServerData: function (sSource, aoData, fnCallback, oSettings) {
                if (oSettings.aaSorting.length)
                {

                    aoData.push({ "name":"popUpId" ,"value": "@Model.popUpId" });
                }


                    oSettings.jqXHR =  $.ajax({

                        "dataType": 'json',
                        "contentType": "application/json; charset=utf-8",
                        "type": "GET",
                        "url": sSource,
                        "data": aoData,
                        "success":
                                    function (msg)
                                    {

                                        var json = jQuery.parseJSON(msg);
                                        fnCallback(json);
                                        $('#' + dataTableId ).removeClass('hidden');
                                    }
                    });

            },
            fnCreatedRow: function( nRow, aData, iDataIndex ) {
                // Bold the grade for all 'A' grade browsers
                $(nRow).attr('onclick', 'getValue("@Model.gridGetValue",this);');
            }

        });

I think my issue is in function FnServerData which is causing ajax requests equal to column in table.Please take a look and help me out.

1 Answer 1

1

I found the error area it was in the following code :

   @for (int i = 0; i < Model.gridColumnsCount; i++)
      {
        if (!Model.gridHideColumns.Contains(i))
        {
            <text>
        tableContainer.fnSetColumnVis(parseInt(@i), false );

            </text>
        }
       }

My above code was causing the many requests.

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

Comments

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.