asp.net mvc - jquery datatable with custom object parameter -
i working mvc , jquery data table. want pass own parameter class along jquery datatable param. here code have used, not working,
index.js
var options = {}; options.bprocessing = true; options.bserverside = true; options.sajaxsource = urlcontent + 'employee/getall'; options.bpaginate = true; options.spaginationtype = "full_numbers"; options.idisplaylength = 10; options.bautowidth = true; options.aocolumns = cols; options.fnserverdata = function (ssource, aodata, fncallback) { $.ajax( { "datatype": 'json', "type": "get", "url": ssource, "data": aodata, "success": function (data) { }, "failure": function (data) { } } ); }; options.fnserverparams = function (aodata) { aodata.push({ "name": "employeemodel", "value": { name : "testing", age:25} }); }; var table = $('#' + tableid).datatable(options);
and mu controller is,
public jsonresult getreportdata(jquerydatatableparamviewmodel param, employeeviewmodel employeemodel) { return new list<employee>(); //// loads database }
the employeemodel
null. did wrong. please me.
i have not done using constructor takes options parameter, used other way, here code :
$('#assets-data-table').datatable({ "serverside": true, "processing": true, "ajax": { "url": "@url.action("get","asset")", "data": function (data) { data.facilitysite = $("#facilitysite").val(); data.building = $("#building").val(); data.manufacturer = $("#manufacturer").val(); data.status = $("#status").val(); } }, "columns": [ { "title": "bar code", "data": "barcode", "searchable": true }, { "title": "manufacturer", "data": "manufacturer", "searchable": true }, { "title": "model", "data": "modelnumber", "searchable": true }, { "title": "building", "data": "building", "searchable": true }, { "title": "room no", "data": "roomno" }, { "title": "quantity", "data": "quantity" }, { "title": "actions", "data": "assetid", "searchable": false, "sortable": false, "render": function (data, type, full, meta) { return '<a href="@url.action("edit","asset")?id=' + data + '" class="editasset">edit</a> | <a href="@url.action("details","asset")?id=' + data + '">details</a> | <a href="@url.action("delete","asset")?id=' + data + '">delete</a>'; } } ], "lengthmenu": [[10, 25, 50, 100], [10, 25, 50, 100]], initcomplete: function () { var input = $('.datatables_filter input').unbind(), self = this.api(), $searchbutton = $('<button>') .text('search') .addclass("btn btn-default") .css("margin-left", "10px") .click(function () { self.search(input.val()).draw(); }) $('.datatables_filter').append($searchbutton); }, "createdrow": function (row, data, index) { if (data["building"] == null) return; switch (data["building"].tolowercase()) { case 'west': $('td:not(:last-child)', row).css({ 'background': 'red', 'color': 'white' }); break; } } });
we specifying custom paramets in ajax call :
"data": function (data) { data.facilitysite = $("#facilitysite").val(); data.building = $("#building").val(); data.manufacturer = $("#manufacturer").val(); data.status = $("#status").val(); }
action looks like:
public actionresult get([modelbinder(typeof(datatablesbinder))] idatatablesrequest requestmodel, advancedsearchviewmodel searchviewmodel) { }
Comments
Post a Comment