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

2 posts, 0 answers
  1. B
    B avatar
    25 posts
    Member since:
    Aug 2010

    Posted 09 Oct 2014 Link to this post

    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();
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2310 posts

    Posted 10 Oct 2014 Link to this post

    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.

     
Back to Top