c# - Change a column in Kendo UI Grid -
i have asp.net mvc 5 application. kendo ui grids calls web api controller retrieve data. have requirement alter contents of column depending on fuel type auto is. on model page created string fuel type. in mvc controller set below:
model.fueltype = "diesel"; //just hardcoded testing in reality dynamically set user in previous screen - set petrol in case need alter column info on partial view have kendo ui grid defined below - on partialview have html.hiddenfor store value of fueltype
@(html.kendo().grid<car.web.models.carviewmodel>() .name("carviewgrid") .columns(columns => { columns.bound(c => c.make).width(180); columns.bound(c => c.modelno).width(280); columns.bound(c => c.enginesize).width(120); columns.bound(c => c.colour).width(65); columns.bound(c => c.mpg).width(65); columns.bound(c => c.carid) .title("include in report") .clienttemplate("<input type=\"checkbox\" name=\"selectedids\" value=\"#=carid#\" class=\"checkboxclass\" />") .width(90) .sortable(false); }) .events(builder => builder.databound("griddatabound")) .htmlattributes(new { style = "height: 420px;" }) .scrollable() .sortable(sortable => sortable .allowunsort(true) .sortmode(gridsortmode.multiplecolumn)) .pageable(pageable => pageable .pagesizes(true) .buttoncount(5)) .datasource(datasource => datasource .ajax() .read(read => read.url("api/car/getcardetails").type(httpverbs.get).data("getcustid")) ) ) i have left line blank in column , need include different column - if fueltyle petrol need have
columns.bound(c => c.numbersparkplugs).width(65); but if fueltype diesel need have
columns.bound(c => c.torque).width(65); both of these string properties on carviewmodel.
has done similar kendo ui grid or can advise in best approach accomplish this?
i don't have kendo mvc project in visualstudio test with, can't utilize if statement:
.columns(columns => { columns.bound(c => c.make).width(180); columns.bound(c => c.modelno).width(280); columns.bound(c => c.enginesize).width(120); columns.bound(c => c.colour).width(65); columns.bound(c => c.mpg).width(65); columns.bound(c => c.carid) .title("include in report") .clienttemplate("<input type=\"checkbox\" name=\"selectedids\" value=\"#=carid#\" class=\"checkboxclass\" />") .width(90) .sortable(false); // added code here... if(model.fueltype == "petrol") columns.bound(c => c.numbersparkplugs).width(65); else columns.bound(c => c.torque).width(65); }) c# asp.net-mvc kendo-ui asp.net-mvc-5 kendo-grid
No comments:
Post a Comment