asp.net mvc 5 - Dynamically load dropdown values depending on row in jquery datatables -


i have mvc web app with jquery code datatables , jeditable. in 1 of views have table projects, users , departments. every project have responsible person. give admin possibility change respnsible person dropdown created on server side. secure don´t break department structures should able choose member department project located. solve have load dropdown depending on entry in department column. far understand datatables, dropdown become loaded if page created shouldn´t possible me change depending on department row. have hind me how solve problem?

here html code:

<script>     $(document).ready(function () {         var otable = $('#projecttable').datatable({             "bserverside": true,             "sajaxsource": "@url.action("projecttablehandler", "managedepartment")",             "alengthmenu": [[10, 25, 50, -1], [10, 25, 50, "all"]],             "bprocessing": true,             "bpaginate": true,             "spaginationtype": "full_numbers",             "sdom": 'ftrlp',             "binfo": false,             "olanguage": {                 "ssearch": "search in departments projects: ",                 "opaginate":                {                    "snext": 'next',                    "slast": '&gt;&gt;',                    "sfirst": '&lt;&lt;',                    "sprevious": 'prev'                }             },             "bdeferrender": true,             "aocolumns": [                 { "sname": "id", "bsearchable": false, "bsortable": false, "bvisible": false },                 { "sname": "id" },                 { "sname": "name" },                 { "sname": "respuser" },                 { "sname": "department" }             ]         });         otable.columnfilter({ splaceholder: "head:after", "aocolumns": [null, null, null, null] });         otable.makeeditable({             "aocolumns": [null,                 { onblur: 'submit' },                 null,                 null],             supdateurl: "@url.action("updateproject", "managedepartment")",         });            });  </script> <hgroup>     <h1>manage projects of own departments</h1> </hgroup>  <fieldset>     <legend id="manageprojectsheadline">projects </legend>        <table id="projecttable" class="display">         <thead>             <tr>                 <th>@html.label("id")</th>                 <th>@html.label("id")</th>                 <th>@html.label("name") </th>                 <th>@html.label("respuser", "responsible user") </th>                 <th>@html.label("department", "department")</th>             </tr>         </thead>         <tbody>         </tbody>         <tfoot>             <tr>                 <th></th>                 <th></th>                 <th></th>                 <th></th>                 <th></th>             </tr>         </tfoot>     </table>     <div class="toolbar">         <input type="button" class="askbutton" id="ask" value="?" />     </div> </fieldset> 

and table handler:

[handleerror(exceptiontype = typeof(businessobjectnotretrievablebyidexception), view = "businessobjectnotfound")] [handleerror] public actionresult projecttablehandler(jquerydatatableparammodel param) {     list<project> allprojects = projectmanagement.getprojectsofdepartmentlist(usermanagement.getallorganisationunitsfromhodorda(usermanagement.getsingle(session.current.usercomparison.getuserid()))).tolist().convertall(i => (project)i);              var isidsearchable = convert.toboolean(request["bsearchable_1"]);     var isnamesearchable = convert.toboolean(request["bsearchable_2"]);     var ispisearchable = convert.toboolean(request["bsearchable_3"]);     var isdepartmentsearchable = convert.toboolean(request["bsearchable_4"]);     ienumerable<project> filteredprojects;     if (!string.isnullorempty(param.ssearch)) filteredprojects = allprojects.where(a => isnamesearchable && a.name.toupper().contains(param.ssearch.toupper()) || ispisearchable && a.secureentity.user != null && (a.secureentity.user.lastname.toupper().contains(param.ssearch.toupper()) || isdepartmentsearchable && a.secureentity.organisationunit != null && a.secureentity.organisationunit.name.toupper().contains(param.ssearch.toupper()));     else filteredprojects = allprojects;     filteredprojects = filteredprojects.where(a => (isvisibilitysearchable && vis == "" || ((a.secureentity.visibility >= 0 && a.secureentity.visibility <= 3) && a.secureentity.visibility == convert.tobyte(vis)))).distinct();     var isidsortable = convert.toboolean(request["bsortable_1"]);     var isnamesortable = convert.toboolean(request["bsortable_2"]);     var ispisortable = convert.toboolean(request["bsortable_3"]);     var isdepartmentsortable = convert.toboolean(request["bsortable_4"]);     var sortcolumnindex = convert.toint32(request["isortcol_0"]);     func<project, string> orderingfunction = (c => sortcolumnindex == 1 && isidsortable ? convert.tostring(c.id) : sortcolumnindex == 2 && isnamesortable ? c.name : sortcolumnindex == 4 && ispisortable ? c.secureentity.user.lastname : sortcolumnindex == 3  && isdepartmentsortable ? c.secureentity.organisationunit.name : "");     var sortdirection = request["ssortdir_0"];     if (sortdirection == "asc") filteredprojects = filteredprojects.orderby(orderingfunction);     else filteredprojects = filteredprojects.orderbydescending(orderingfunction);     if (param.idisplaylength != -1) filteredprojects = filteredprojects.skip(param.idisplaystart).take(param.idisplaylength);     var projectstringlist = new list<string[]>();     foreach (var project in filteredprojects)     {         var url = url.action("projectdetails", "projects", new { id = project.id });          projectstringlist.add(new string[] { convert.tostring(project.id), "<a href='" + url + "'>" + convert.tostring(project.id) + "<a>", project.name, "" + project.secureentity.user.firstname + " " + project.secureentity.user.lastname,  project.secureentity.organisationunit.name });     }     return json(new { secho = param.secho, itotalrecords = allprojects.count(), itotaldisplayrecords = filteredprojects.count(), aadata = projectstringlist }, jsonrequestbehavior.allowget); } 


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -