Question

I am using the following code to create a datatable and allow export to various formats using TableTools. I am pulling data via ajax, but only at the start, so all filtering and sorting etc, is on the client side, and bServerSide is set to false. If I populate the rows in the table directly I can get all of my filtered results, but if I use the ajax call (which allows me to take advantage of the "Processing..." message) it exports only the current page of data.

    var oTable = $('#dataTableAccountList').dataTable({
        "sDom": "<'row'<'col-lg-6'l><'col-lg-6'Tf>r>t<'row'<'col-lg-6'i><'col-lg-6'p>>",
        "bServerSide": false,
        "bDeferRender": true,
        "sAjaxSource": '@Url.Action("AccountLoadThroughAjaxCall", "AccountList")',
        "bProcessing": true,
        "oTableTools": {
            "sSwfPath": "/Scripts/TableTools-2.2.0/swf/copy_csv_xls_pdf.swf",
            "aButtons": [
            {
                "sExtends": "copy",
                "oSelectorOpts": { filter: 'applied', order: 'current' }
            },
            {
                "sExtends": "xls",
                "oSelectorOpts": { filter: 'applied', order: 'current' },
                "sFileName": "AccountList_yyyy-MM-dd_hh.mm.ss.xls"
            },
            {
                "sExtends": "pdf",
                "oSelectorOpts": { filter: 'applied', order: 'current' },
                "sFileName": "AccountList_yyyy-MM-dd_hh.mm.ss.pdf",
                "sPdfOrientation": "landscape",
                "sPdfMessage": "Account List" + ($('div.dataTables_filter input').length > 0 ? " Filter: " + $('div.dataTables_filter input').val() : "")
            },
            {
                "sExtends": "print",
                "oSelectorOpts": { filter: 'applied', order: 'current' },
            }
            ]
        }
    });

Again I am sure I am missing something simple, but can't see what it is.

Thanks in advance!

Was it helpful?

Solution

I was not able to use sAjaxSource with bServerSide:false. I don't think you can. I had to convert the json object to a list of lists and use the aaData parameter instead.

see here: http://datatables.net/release-datatables/examples/data_sources/ajax.html and here: http://datatables.net/examples/data_sources/js_array.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top