0

I am using datatable.js with MVC4 web application. I am try to pass array data in fnServerParams.

Here I create a array object called array to passing data to server side.

Please see my code below:

function GetTaxInvoices(IsInital, TaxInvoiceIds) {

    alert("message : IsInital :- " + IsInital + " , TaxInvoiceIds :- " + TaxInvoiceIds);

    var elementName = "#tblCreatedTaxInvoices";

    ClearData(dtTable2);

    var array = [51, 52];

    ajaxUrl = (IsInital) ? null : '@Url.Action("GetCreatedTaxInvoices", "Invoice")';

    dtTable2 = $(elementName).dataTable({
        bProcessing: true,
        bLengthChange: false,
        sAjaxSource: ajaxUrl,
        traditional: true,
        "fnServerParams": function (aoData) {
            aoData.push(
                            { "name": "TaxInvoiceIds", "value": array }
            );
        },
        aoColumns: [
            { sTitle: "Id", bSortable: false, bVisible: false, },
            { sTitle: "PoBox Number", bSortable: false, },
            { sTitle: "Email", bSortable: false, },
            { sTitle: "Owner", bSortable: false, },
            { sTitle: "General Tax", bSortable: false, },
            { sTitle: "Consumption Tax", bSortable: false, },
            { sTitle: "Due Amount", bSortable: false, },
            { sTitle: "Date", bSortable: false, },
            { sTitle: "Detailes", bSortable: false, },
        ],
    });

}

But it always shows null.

enter image description here

7
  • Can you update your question with the body of the request? Commented Jan 19, 2015 at 16:21
  • Sure... Sorry for my bad english... Commented Jan 19, 2015 at 16:31
  • Actually i try to pass a array in my Controller action. I already use '$.makeArray' but it's not working. Commented Jan 19, 2015 at 16:32
  • What happens if you change long[] TaxInvoiceIds to string[] TaxInvoiceIds or even just string TaxInvoiceIds? Commented Jan 19, 2015 at 16:33
  • Yes, it's working when i replace the 'string[] ' with 'string' , But you mean it's not possible to use a array ? Commented Jan 19, 2015 at 16:42

1 Answer 1

1

try this:

 aoData.push(
      { "name": "TaxInvoiceIds[]", "value": array }
 );

https://github.com/DataTables/DataTablesSrc/commit/a3f57e4

or this: http://www.justinmichaels.net/custom-serverside-filtering-with-jquery-datables-and-asp-net-mvc3 (I am using this way).

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.