简体   繁体   English

基于列的Kendo网格行颜色

[英]Kendo Grid Row Colors based on value of column

Okay, so what I need to do here is display the grid rows with different colors based on the value of a column of the row. 好的,所以我需要在此基于行的一列值以不同的颜色显示网格行。 Here is my current code for the grid: 这是我当前的网格代码:

 @(Html.Kendo().Grid<iPlan.Syspro.Beekman.Portal.Agents.Models.SalesOrderViewModel>()
.Name("Inbox")
.HtmlAttributes(new { style = "height:80vh; width:80vw;" })
.Columns(columns =>
{
    columns.Bound(c => c.SalesOrder).Width(60);
    columns.Bound(c => c.Status).Width(60);
    columns.Bound(c => c.Date).Width(60);
    columns.Bound(c => c.DaysOutstanding).Width(80);
    //columns.Bound(c => c.Available).Width(60);
    columns.Template(@<text></text>).Width(60).ClientTemplate("<a class='k-button k-button-icontext k-grid-edit' href='/Inbox/SalesOrderDetail?SalesOrder=#=SalesOrder#'><span class='k-icon k-edit'></span>View</a>").Title("Detail");       
    columns.Template(@<text></text>).Width(60).ClientTemplate("<a class='k-button k-button-icontext k-grid-edit' href='/Inbox/GetDeliveryNote?SalesOrder=#=SalesOrder#'><span class='k-icon k-edit'></span>View</a>").Title("Delivery Note");
    columns.Template(@<text></text>).Width(60).ClientTemplate("<a class='k-button k-button-icontext k-grid-edit' href='/Inbox/GetDealerOrder?SalesOrder=#=SalesOrder#'><span class='k-icon k-edit'></span>View</a>").Title("Dealer order");
    columns.Template(@<text></text>).Width(60).ClientTemplate("<a class='k-button k-button-icontext k-grid-edit' href='/Inbox/GetFitmentFee?SalesOrder=#=SalesOrder#'><span class='k-icon k-edit'></span>View</a>").Title("Fitment invoice");    

})
.Selectable()
.Scrollable()
.Sortable()
.Groupable()
.Filterable()
.Pageable(pageable => pageable
    .Refresh(true)
    .PageSizes(true)
    .ButtonCount(5))
.DataSource(dataSource => dataSource
    .Ajax()
    .Read(read => read.Action("SalesOrders_Read", "Inbox"))        
    )        
  )

Have anyone done this already? 有人做过吗? I'm relatively new to kendo and I have no clue on how to do this. 我对剑道比较陌生,我对如何做到这一点一无所知。 If anyone can tell me how to do this or share a link to something similar that would be great. 如果有人可以告诉我如何执行此操作或共享指向类似内容的链接,那将是很好的。 Thanks 谢谢

I've got exaxtly what you are looking for. 我已经得到了您要找的东西。 Just tested and it's working fine. 刚刚测试过,它工作正常。

@(Html.Kendo().Grid(Model)
        .Name("GridLogIn")
        .Events(e => e.DataBound("LineItems_Databound"))
        .Columns(columns =>
    {
        columns.Bound(p => p.SomeValueRow).Title("Użytkownik").Width(139).HtmlAttributes(new { style = "text-align:center" }).HeaderHtmlAttributes(new { style = "text-align:center" });

    })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(100)
        .ServerOperation(true)
        .Read(read => read.Action("AjaxBinding", "TableLogIn"))
     )
)

<script>

    function LineItems_Databound() {

        var grid = $("#GridLogIn").data("kendoGrid");
        var data = grid.dataSource.data();

        $.each(data, function (i, row) {
            var status = row.SomeValueRow;

            if (status == 0) {
                $('tr[data-uid="' + row.uid + '"] ').css("background-color", "#99cc99"); //green
            }
            else
            {
                $('tr[data-uid="' + row.uid + '"] ').css("background-color", "#ffffb2");  //yellow
            }


        });
    }

</script>

Please write if you have any problems or questions. 如果您有任何问题或疑问,请写信。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM