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

[Solved] How to display grid cell data based on a conditional

3 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jim
Top achievements
Rank 1
Jim asked on 19 Sep 2011, 06:18 PM


I need to populate the first cell in rows with a linkaction button on if I have a valid item,,,  My grid is below


<div id="thePanel" class="gridSection prepend-1 span-22 last">
        <% Html.Telerik().Grid(Model)
        .Name("Grid")
        .ClientEvents(events => events
                .OnRowSelect("onRowSelected")
                .OnLoad("onLoad")
                
            )
        .DataKeys(keys => keys.Add(p => p.Id))
        .Columns(columns =>
            {
-- this only need to show the button link if data is correct Sudo code wrpping it
if (value = newvalue)
{               

columns.Bound(x => x.Id).Title("AtoP").Format(Html.ActionLink("Create project", "CreateProject", new { id = "{0}" }).ToHtmlString()).Encoded(false).Width(60);  
}
Else
{
 -----empty column.
}

                columns.Bound(p => p.Id).Hidden(true);
                columns.Bound(p => p.Company);//.Width(100);
                columns.Bound(p => p.DeliveryUtilityAccountNumbers);//.Width(200);
                columns.Bound(p => p.FacilityName);//.Width(100);
                columns.Bound(p => p.Notes).Width(150);
                columns.Bound(p => p.Description);//.Width(125);
                columns.Bound(p => p.StartDateTime);//.Width(75);
                columns.Bound(p => p.EndDateTime);//.Width(75);
                columns.Bound(p => p.ScheduleDateTime);//.Width(75);
                columns.Bound(p => p.Status);//.Width(75);
            })
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select("BindGrid", "Audits")
         )
        .Scrollable(scrolling => scrolling.Height(400))
        .Reorderable(reorder => reorder.Columns(true))
        .Selectable()
        .Resizable(resizing => resizing.Columns(true))
        .Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(o => o.StartDateTime).Ascending()))
        .Filterable()
        .Pageable(paging =>
            paging.PageSize(50))
        .Render();
        %>
    </div>

3 Answers, 1 is accepted

Sort by
0
Jim
Top achievements
Rank 1
answered on 20 Sep 2011, 05:15 PM
So I figured it out after several hours of hair pulling and head banging.   it is a follows:
I created an entry for my style sheet hiding text:

TD.hidden-link a
{
    display: none;
}

Then on the Cell action did the following:

.CellAction( cell =>
        {
            if (cell.DataItem.Id.Equals(cell.DataItem.pid) && cell.Column == cell.Grid.Columns[0])
            {
                cell.HtmlAttributes["class"] = "hidden-link";
            }
        })
  It was easy enough since i knew the column that needed to be clear will always be index zero. 

Pretty simple after the fact!
0
Jim
Top achievements
Rank 1
answered on 27 Sep 2011, 06:36 PM
This works until you page the Grid :(
0
R
Top achievements
Rank 1
answered on 30 Sep 2011, 06:01 AM
Yes I want to achieve something similar.  In my case I have a boolean field that I want to display 'Yes'/'No' for in the grid cell (using MVC3/Razor). It should be easy, and I've wasted enough time on this already. Surely I shouldn't have to redesign my ViewModel to cater for this.
Tags
Grid
Asked by
Jim
Top achievements
Rank 1
Answers by
Jim
Top achievements
Rank 1
R
Top achievements
Rank 1
Share this question
or