asp.net mvc - mvc - jQuery ajax datatable actionlink -
i have datatable in data (from database) being filled ajax, want new tablerow "details" show more details of selected item, table allows data database. here view
<script language="javascript" type="text/javascript"> $(document).ready(function () { $('#mydatatable').datatable({ "bprocessing": false, "bserverside": true, "sajaxsource": 'ajaxdataprovider', "aocolumns": [ { "sname": "id", }, { "sname": "student_naam" }, { "sname": "klas" }, { "sname": "adres" }, { "sname": "woonplaats" }, { "sname": "details" } ] }) }); </script>
and have table beneath code including this:
<td> @html.actionlink("details", "index", "studentgegevens", new {id = item.studentnr}) </td>
here controller
public actionresult ajaxdataprovider(jquerydatatableparammodel param) { var allstudents = hoi.student.tolist(); ienumerable<student> filteredstudents; if (!string.isnullorempty(param.ssearch)) { //used if particulare columns filtered var roepnaamfilter = convert.tostring(request["ssearch_1"]); var adresfilter = convert.tostring(request["ssearch_2"]); var woonplaatsfilter = convert.tostring(request["ssearch_3"]); var klasfilter = convert.tostring(request["ssearch_4"]); //optionally check whether columns searchable @ var isnamesearchable = convert.toboolean(request["bsearchable_1"]); var isaddresssearchable = convert.toboolean(request["bsearchable_2"]); var istownsearchable = convert.toboolean(request["bsearchable_3"]); var isclasssearchable = convert.toboolean(request["bsearchable_4"]); filteredstudents = hoi.student.tolist() .where(c => isnamesearchable && c.roepnaam.tolower().contains(param.ssearch.tolower()) || isaddresssearchable && c.adres.tolower().contains(param.ssearch.tolower()) || istownsearchable && c.woonplaats.tolower().contains(param.ssearch.tolower()) || isclasssearchable && c.klas.tolower().contains(param.ssearch.tolower())); } else { filteredstudents = allstudents; } var isnamesortable = convert.toboolean(request["bsortable_1"]); var isaddresssortable = convert.toboolean(request["bsortable_2"]); var istownsortable = convert.toboolean(request["bsortable_3"]); var isclasssortable = convert.toboolean(request["bsortable_4"]); var sortcolumnindex = convert.toint32(request["isortcol_0"]); func<student, string> orderingfunction = (c => sortcolumnindex == 1 && isnamesortable ? c.roepnaam : sortcolumnindex == 2 && isclasssortable ? c.klas : sortcolumnindex == 3 && isaddresssortable ? c.adres : sortcolumnindex == 4 && istownsortable ? c.woonplaats : ""); var sortdirection = request["ssortdir_0"]; // asc or desc if (sortdirection == "asc") { filteredstudents = filteredstudents.orderby(orderingfunction); } else { filteredstudents = filteredstudents.orderbydescending(orderingfunction); } var displayedstudents = filteredstudents.skip(param.idisplaystart).take(param.idisplaylength); var result = c in displayedstudents select new[] { convert.tostring(c.studentnr), c.roepnaam, c.klas, c.adres, c.woonplaats, "here thing dont know fill in" }; return json(new { secho = param.secho, itotalrecords = allstudents.count(), itotaldisplayrecords = filteredstudents.count(), aadata = result }, jsonrequestbehavior.allowget); }
and public ints
public class jquerydatatableparammodel { public string secho { get; set; } public string ssearch { get; set; } public int idisplaylength { get; set; } public int idisplaystart { get; set; } public int icolumns { get; set; } public int isortingcols { get; set; } public string scolumns { get; set; } }
i know should put @ var result.
everything displayed correctly except link, tried url.action without luck, doesn't give link back.
not sure kind of detail data want show, can check method: fnrender or mrender, below sample.
"aocolumns": [ { "sname": "id", }, { "sname": "student_naam" }, { "sname": "klas" }, { "sname": "adres" }, { "sname": "woonplaats" }, { "sname": "details", "mrender": function ( data, type, full ) { return '<a href="'+data+'">download</a>'; } } ]
Comments
Post a Comment