razor - In .Net MVCGrid I'm unable to pass additional query options using client side bindings -


hi have grid need send values retrievedatamethod. using 2 drop down menus filters because menus don't relate directly columns in grid can't use filter option.

i idea of using client side binding because clean , avoids me needing write jquery.

the code grid is

public static mvcgridbuilder<batch> buildgrid(griddefaults griddefaults, columndefaults columndefaults)     {         return new mvcgridbuilder<batch>(griddefaults, columndefaults)             .addcolumns(cols =>             {                 cols.add("batchid")                     .withheadertext("batch id")                     .withvalueexpression(p => p.batchid.trim());                 cols.add("partnumber").withheadertext("part number")                     .withvalueexpression(p => p.partnumber.trim());                 cols.add("adjustedqty")                     .withhtmlencoding(false)                     .withheadertext("adjusted qty")                     .withvalueexpression((p, c) => c.urlhelper.action("adjustbatchquantity", "batch"))                     .withvaluetemplate("<a href='#' id='adjustedqty' style='display: inline;' data-type='text' data-pk='{model.batchid}' data-url='adjustbatchquantity' data-title='adjust quantity' class='editable editable-click' >{model.adjustedqty}</a>");                 cols.add("updatedate")                     .withheadertext("update date")                     .withvalueexpression(p => p.updatedate.toshortdatestring());             })             .withadditionalqueryoptionnames("familyid", "colorid")             .withadditionalsetting("renderloadingdiv", true)             .withdefaultsortcolumn("updatedate")             .withdefaultsortdirection(sortdirection.dsc)             .withfiltering(true)             .withretrievedatamethod(context =>             {                 var options = context.queryoptions;                  var batchrepo = dependencyresolver.current.getservice<ibatchrepository>();                 var productrepo = dependencyresolver.current.getservice<iproductrepository>();                  int family = 0, bottleqty = 0, colorid = 0, count;                  if (options.additionalqueryoptions.containskey("familyid"))                 {                     var temp = options.getadditionalqueryoptionstring("familyid");                      if (temp != null)                     {                         family = int.parse(options.getadditionalqueryoptionstring("familyid"));                     }                 }                  if (options.additionalqueryoptions.containskey("colorid"))                 {                     var color = options.getadditionalqueryoptionstring("colorid");                      if (color != null)                     {                         var temp = color.split('_');                          if (temp[0] != string.empty)                         {                             colorid = convert.toint32(temp[0]);                         }                          if (temp.length > 1)                         {                             bottleqty = convert.toint32(temp[1]);                         }                     }                 }                  var partnumbers = productrepo.getpartnumbersbyfamilycolorquantity(family, colorid, bottleqty);                 var items = batchrepo.getbatchehistoryrecordsforgrid(options.getlimitoffset(), options.getlimitrowcount(), partnumbers, out count);                  if (!string.isnullorwhitespace(options.sortcolumnname))                 {                     switch (options.sortcolumnname.tolower().replace(" ", string.empty))                     {                         case "batchid":                             items = items.orderby(p => p.batchid).tolist();                             break;                         case "partnumber":                             items = items.orderby(p => p.partnumber).tolist();                             break;                         case "adjustedqty":                             items = items.orderby(p => p.adjustedqty).tolist();                             break;                         case "updatedate":                             items = items.orderby(p => p.updatedate).tolist();                             break;                     }                 }                  if (options.sortdirection.tostring().tolower() == "dsc")                 {                     items.reverse();                 }                  return new queryresult<batch>() { items = items, totalrecords = count };             });     } 

and relevant parts of html

@scripts.render("~/areas/mfgtransactions_mvc/scripts/createbatchdropdownfilters.js")  @scripts.render("~/bundles/bootstrapgridscripts") @styles.render("~/bundles/bootstrap3/bootstrapgridcss");  <script>     $(document).ready(function () {         $('#adjustedqty').editable();         $.fn.editable.defaults.mode = 'inline';         $.fn.editable.defaults.ajaxoptions = {             ajaxoptions: {                 type: 'post',                 datatype: 'json'             }         };     }); </script>  ....  <div class="form-group ">     @html.labelfor(x => x.familyid)     @html.dropdownlistfor(x => x.familyid, model.familylistitems, "select family", new { @class = "form-control", data_mvcgrid_type = "additionalqueryoption", data_mvcgrid_option = "familyid", data_mvcgrid_apply_additional = "change" })  </div>   <div class="form-group ">      @html.labelfor(x => x.color)      @html.dropdownlistfor(x => x.color, model.colorlistitems, "select colour", new { @class = "form-control", data_mvcgrid_type = "additionalqueryoption", data_mvcgrid_option = "colorid", data_mvcgrid_apply_additional = "change" })  </div> 

the problem seems additionalqueryoption event isn't been triggered. when debug code can see line var options = context.queryoptions; has additionalqueryoptions there no values them.

is there step have missed setting ?

my bad, had removed

@scripts.render("~/mvcgridhandler.axd/script.js") 

and placed in bundle config, didn't seem work there.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -