This is a migrated thread and some comments may be shown as answers.

Possible to programatically get column value from body of grid command?

1 Answer 338 Views
Grid
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 1
B asked on 09 Oct 2014, 06:58 PM
Hi -

I have the grid below and am trying to get the value of a certain column to dynamically render a set of workflow buttons based on that value.  Is it possible to do this?


Html.Kendo().Grid<ViewModelName>()
   .Name("GridName")
   .ToolBar(commands => commands.Create())
   .DataSource(ds => 
  ds.Ajax()
  .Read("Select", "EmpActivitySummary", new { EmpActivityId = RouteData.Values["id"] })
  .Update("Update", "EmpActivitySummary", new { EmpActivityId = RouteData.Values["id"] })
  .Destroy("Delete", "EmpActivitySummary")
  .Create("Insert", "EmpActivitySummary", new { EmpActivityId = RouteData.Values["id"] })
  .Model(m =>
  {
  m.Id(x => x.Id);
  m.Field(x => x.EmpActivityId).Editable(false);
  m.Field(x => x.Id).Editable(false);
  m.Field(x => x.Approved).Editable(false);
  })
   )  
   .PrefixUrlParameters(false)
   .Columns(r =>
   {           
r.Command(com =>
{
com.Edit();
com.Destroy();

var currentStatus = r.Template(model => model.Approved);  // <--------------- I'm trying to get the value of this column
var utilities = new WorkflowUtilities("Workflow Name");
var steps = utilities.GetSteps(currentStatus);

foreach (var step in steps.Where(step => Roles.IsUserInRole(step.RequiredRole)))
{
com.Custom(step.ButtonText).Click("ProcessWorkflowStep").SendDataKeys(true);                        
}

}).Title("Commands").Width(60);
r.Bound(x => x.Id).Width(100);
r.Bound(x => x.Field);
r.Bound(x => x.Quantity);
r.Bound(x => x.Price).AsCurrency();
r.Bound(x => x.Date);
r.Bound(x => x.Approved);
    
   })
   .Render();

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 10 Oct 2014, 07:44 AM
Hello Brandon,


In an Ajax bound Grid the data is not available during Grid initialization, but retrieved later via ajax. This is why the value of the column could not be retrieved in the Grid code. A sample approach would be to bind to the dataBound event of the Grid (which is fired after the data is available and the rows are rendered), retrieve the model associated with each row, check the column value and manually inject the code for the custom commands.
E.g.
function dataBound(e) {
    var grid = this;
 
    grid.tbody.find("tr[role='row']").each(function () {
        var model = grid.dataItem(this);
        var approved = model.Approved;
 
        //append command markup
        //$(this).find("td:eq(1)")...
    });
}

Regards,
Dimiter Madjarov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
B
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or