Tuesday, 15 June 2010

Jquery Datatables adding extra columns for crud actions c# -



Jquery Datatables adding extra columns for crud actions c# -

i trying add together 2 columns crud actions ie select , delete displaying image in column link via primary key. cannot show or says have wrong number of columns. table view

<table class="searchresultstable"> <thead> <tr> <th> @html.displayname("user id") </th> <th> @html.displayname("user email") </th> <th> @html.displayname("user role") </th> <th> @html.displayname("select") </th> <th> @html.displayname("delete") </th> </tr> </thead> <tbody> @foreach (var item in model) { <tr> <td> @html.displayfor(modelitem => item.user_pk) </td> <td> @html.displayfor(modelitem => item.user_email) </td> <td> @html.displayfor(modelitem => item.user_type) </td> <td> <a href="@url.action("getuser", "user", new { id = item.user_pk })"> <img src="/content/images/selecticon.gif" alt="my image" /> </a> </td> <td> <a href="@url.action("getuser", "user", new { id = item.user_pk })"> <img src="/content/images/deleteicon.gif" alt="my image" /> </a> </td> </tr> } </tbody>

jquery

<script type="text/javascript"> $(document).ready(function () { $(".searchresultstable").datatable({ 'bserverside': true, 'bprocessing': true, 'sajaxsource': '/user/filteredusers', "bjqueryui": true, "bautowidth": false, "bpaginate": true, "spaginationtype": "full_numbers", "idisplaylength": 25, "aocolumns": [ { "sname": "user_pk", "bsearchable": false, "bsortable": false, }, { "sname": "user_email" }, { "sname": "user_role" }, //{ // "mdata": null, "bsearchable": false, // "bsortable": false, "sclass": "editcontrol", // "sdefaultcontent": '<img src="/content/images/selecticon.gif" />' //}, //{ // "mdata": null, "bsearchable": false, // "bsortable": false, "sclass": "editcontrol", // "sdefaultcontent": '<img src="/content/images/deleteicon.gif" />' //} ] /* create first , lastly columns not sortable */ }); }); </script>

}

controller

// get: /user/details/5 public actionresult filteredusers(jquerydatatableparammodel param) { restclient restclientobject = new restclient("http://domain"); var request = new restrequest("api/user/", method.get); request.addparameter("page", param.idisplaystart); request.addparameter("pagesize", param.idisplaylength); if (param.ssearch != null) request.addparameter("username", param.ssearch); irestresponse<pager<usersummarymodel>> response = restclientobject.execute<pager<usersummarymodel>>(request); ienumerable<string[]> result = null; seek { result = c in response.data.pagedset select new[] { convert.tostring(c.user_pk), c.user_email, c.user_type }; } grab { result = enumerable.empty<string[]>(); } homecoming json(new { seco = param.secho, itotalrecords = response.statuscode == httpstatuscode.ok ? response.data.totalrecordsize : 0, itotaldisplayrecords = response.statuscode == httpstatuscode.ok ? response.data.totalrecordsize : 0, aadata = result }, jsonrequestbehavior.allowget); }

if not set rows in result array in controller says have wrong columns numbers.. if leave them out of jquery dont error columns not populated. please tell me how this

c# jquery asp.net-mvc datatables

No comments:

Post a Comment