jquery - Display text on button and change color of the button Kendo UI -


i want display text on button based on value database.

so, button text varies in each row(ex: in service, expired, 30 days expire).

1) how can display text in button in kendo row ?

2) want change color of button based on above 3 values. (ex: in service - green, expired - red, 30 day expire - yellow)

i want display button in custom command button in below code

how can ?

@(html.kendo().grid(model)        .name("grid")        .columns(columns =>        {            columns.bound(c => c.username).title("user").filterable(false);                           columns.bound(c => c.role).title("role");                           //columns.command(command => command.custom().click("showdetails"));        })        .htmlattributes(new { style = "height: 500px;" })        .sortable()        .scrollable(x => x.height(400))        .filterable()        .pageable(x => x.enabled(true).previousnext(false).pagesizes(true))    ) 

looks doing serverside binding grid. in case need use template() method of column builder.

i tried replicate scenario. have model following definition:

 public class statusmodel     {         public string col1 { get; set; }         public string status { get; set; }     } 

then in controller, creating list 3 items below:

public actionresult index()         {             var data = new list<statusmodel>()             {                 new statusmodel {col1="row 1",status="in service" },                 new statusmodel {col1="row 2",status="expire" },                 new statusmodel {col1="row 3",status="30 days expire" },             };                 return view(data);         } 

and in view here how need define grid:

@(html.kendo().grid(model)                   .name("kgrid")                   .columns(columns =>                   {                       columns.bound(c => c.col1).title("column 1");                       columns.bound(c => c.status).template(@<text>                         @if (@item.status == "in service")                         {                             @html.kendo().button().name("kbutton").content(@item.status).htmlattributes(new { style = "background-color:green;color:white;width:150px" })                         }                         else if (@item.status == "expire")                         {                             @html.kendo().button().name("kbutton").content(@item.status).htmlattributes(new { style = "background-color:red;color:white;width:150px" })                         }                         else                         {                             @html.kendo().button().name("kbutton").content(@item.status).htmlattributes(new { style = "background-color:orange;color:white;width:150px" })                         }                     </text>);                   })             ) 

you can optimize code further doing if else decide on css class can apply , single call kendo.button() , pass css class html attribute.

hope helps.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -