简体   繁体   中英

server side data loading from C# in jquery datatable

Hi i have successfully implemented jquery data table server side call,but i am unable to load data in html view it just says processing here is my Js code

 $('#internetTable').dataTable({
    'bProcessing': true,
    'bServerSide': true,
    'sAjaxSource': 'api/values/GetInternetSales'
    "aoColumns": [
        { "mData": "Calls" },
        { "mData": "LevelOneOperators" },
        { "mData": "LevelTwoOperators" },
        { "mData": "Issueraised" },
        { "mData": "SalesDate" },
        { "mData": "AutomaticResponses" }

    ]
});

and this is html code

<table id="internetTable" class="table table-bordered table-hover">
            <thead>
                <tr>
                    <th >Date</th>
                    <th>Issue Raised</th>
                    <th>Level One Operators</th>
                    <th >Level Two Operators</th>
                    <th>Automatic Responses</th>
                    <th>Calls</th>
                </tr>
            </thead>
        </table>

And the response am getting from server is

{"sEcho":"2","iTotalRecords":10,"iDisplayStart":1,"iDisplayEnd":1,"iDisplayLength":10,"iTotalDisplayRecords":100,"InternetDataList":[{"Calls":"320","LevelOneOperators":"1","LevelTwoOperators":"7","Issueraised":"1","SalesDate":"2010-11-25T00:00:00","AutomaticResponses":235}]}

Now,just want to ask that what modifications in JS code do i need to do to parse it in table,as i have searched alot but could'nt get any solution.

Got the answer i need to add following code in js:

$('#internetTable').dataTable({
    'bProcessing': true,
    'bServerSide': true,
    "sServerMethod": "GET",
    // to enable Pagination
    "sPaginationType": "full_numbers",
    'sAjaxSource': 'api/values/GetInternetSales',
    "sAjaxDataProp": "InternetDataList",
    "aoColumnDefs": [{
        "mData": "InternetDataList"
    }],
    "aoColumns": [
        { "mData": "Calls" },
        { "mData": "LevelOneOperators" },
        { "mData": "LevelTwoOperators" },
        { "mData": "Issueraised" },

        { "mData": "AutomaticResponses" },
               { "mData": "SalesDate" }


    ]
});

As,here the sAjaxDataProp is your data name as in my case it is InternetDataList and default it is aadata

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM