asp.net mvc 3 - jquery datatables actionlink how to add -


i have been searching last few hours, , unfortunately cannot seem find example of how populate datatable action edit , delete link column using .net , mvc.

here have far, how add action link? missing?

<script type="text/javascript"> $(document).ready(function () {     $('#mydatatable').datatable({         bprocessing: true,         sajaxsource: '@url.action("index1", "default1")'     });  }); </script>  <div id="container"> <div id="demo">     <table id="mydatatable">         <thead>             <tr>                 <th>                     roleid                 </th>                 <th>                     rolename                 </th>                 <th>                     userid                 </th>                 <th>                     username                 </th>             </tr>         </thead>         <tbody>          </tbody> </table>     </div> </div> 

i want add in last column;

    <td>         @html.actionlink("edit", "edit", new {id=item.primarykey}) |         @html.actionlink("details", "details", new { id=item.primarykey }) |         @html.actionlink("delete", "delete", new { id=item.primarykey })     </td> 

but cannot figure out how it.

you use aocolumns property fnrender function add custom columns. can't use html.actionlink helper because have generate links dynamically javascript. aocolumns property helps configure each columns, if don't want configure particular column pass null else have pass object({}).

the fnrender function helps create links using values of other columns. can use oobj.adata values of other column id generate links.

<script type="text/javascript">         $(document).ready(function () {         $('#mydatatable').datatable({             bprocessing: true,                      sajaxsource: '@url.action("index1", "default1")',             aocolumns: [                       null, // first column (roleid)                       null, // second column (rolename)                         null, // third (userid)                       null, // fourth (username)                        {     // fifth column (edit link)                         "sname": "roleid",                         "bsearchable": false,                         "bsortable": false,                         "fnrender": function (oobj)                                                       {                             // oobj.adata[0] returns roleid                             return "<a href='/edit?id="                                  + oobj.adata[0] + "'>edit</a>";                         }                        },                         { }, // repeat samething details link                         { }  // repeat samething delete link                     ]      });   });  </script> 

another important thing in json output return server, edit column have return 1, 2, 3 or anything.

reference: http://jquery-datatables-editable.googlecode.com/svn/trunk/ajax-inlinebuttons.html


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -