Telerik 网格基于多个日期范围的自定义格式

发布于 2024-10-21 13:48:41 字数 5042 浏览 7 评论 0原文

我可以想到至少有 3 种方法可以做到这一点:-

第一种(理想)- 在大约有 8 列的单个 telerik 网格中,第 1 列将列出所有表条目,接下来的 6 列用于显示为每个条目提交的不同日期但不一定每个条目都有一个值,最终的 col 将链接到单独页面上的每个条目,以允许通过日期选择器提交新日期或进行编辑。

主要问题是我需要能够根据每个列以不同的颜色显示网格上的每个日期,我的意思是我在第一列中记录一个日期,该日期每年更新一次,所以如果> 6个月,那么它的颜色1、>1 个月颜色 2、<1 个月颜色 3,最后如果过去 1 年标记则颜色 4。

其他列也有 2 种不同的可能续订长度。

第二个 - 每个不同的更新长度都会有自己的网格,因此第一个代表 1y,第二个代表第二个长度,第三个代表第三个长度。

第三(可能)- 4 个网格来替换颜色,它只会显示每个类别,因此 1 个网格将显示超过 6 个月的所有条目,网格 2 将显示大于 1 个月,网格 3 将显示小于 1 个月,网格 4 将显示过去的时间长度。

我不知道如何最好地以符合我需要的方式对日期进行排序,但我认为选项 1 是可能的,或者选项 3 是最简单的。

编辑 -

using System
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace (...).Models.DTO
{
    public class ...DTO
    {
        public int Id { get; set; }
        public string Name { get; set; }
        //public string C1D
        //{
        //    get
        //    {
        //        if (C1D < DateTime.Today.AddDays(-183)) return "Green";
        //    }
        //}
        public string C1D
        {
            get
            {
                if ((C1D = DateTime.ParseExact(C1D, "yyyy/mm/dd", null)) < DateTime.Today.AddDays(-183)) return "Green";
            }
            set;
        }
        public string C2D { get; set; }

这里它显示了我如何尝试以两种不同的方式设置 C1D 以及对于 C2D 我通常如何设置进入 Telerik 网格的列。

[GridAction]
    public ActionResult _List(int? Id)
    {
        List<...DTO> ret = new List<...DTO>();
        _db.(...).ToList().ForEach(x =>
        {
            ret.Add(new ...DTO
            {
                Id = x.Id,
                Name = x.(...)Name,
                C1D = (x.C1SD.HasValue) ? x.C1SD.Value.ToShortDateString() : "",
                C2D = (x.C2SD.HasValue) ? x.C2SD.Value.ToShortDateString() : "",

这就是我在控制器中进行设置以在 Telerik 网格中显示数据的方式。

下面是我如何设置视图

<% Html.Telerik().Grid<(...).Models.DTO.(...)DTO>()
   .Name("...List")
   .DataKeys(dk => dk.Add(x => x.Id))
   .Columns(c =>
       {
           c.Bound(x => x.Name);
           c.Bound(x => x.C1D)
               .Title("...");
           c.Bound(x => x.C2D)
               .Title("...");
           c.Bound(x => x.C3D)
               .Title("...");
           c.Bound(x => x.C4D)
               .Title("...");
           c.Bound(x => x.C5D)
               .Title("...");
           c.Bound(x => x.C6D)
               .Title("...");
           c.Bound(x => x.C7D)
               .Title("...");
       })
    .Sortable()
    .Filterable()
    .DataBinding(db => db.Ajax().Select("_List", "..."))
    .Render();
%>

编辑 2 - 我也尝试过

.ClientEvents(e => e.OnDataBound("onDataBound"))

function onDataBound(e) {
    if (e.dataItem.C1D > DateTime.Today.AddDays(183)) {
        e.cell.style.backgroundColor = "green";
    }
    if (e.dataItem.C1D > DateTime.Today.AddDays(30)) {
        e.cell.style.backgroundColor = "orange";
    }
    if (e.dataItem.C1D > DateTime.Today) {
        e.cell.style.backgroundColor = "red";
    }
    if (e.dataItem.C1D <= DateTime.Today) {
        e.cell.style.backgroundColor = "purple";
    }

}

,到达此页面后,它会中断代码并显示“Microsoft JScript 运行时错误:'dataItem.C1D' 为 null 或不是对象”和“Microsoft JScript 运行时错误:'cell.style' 为 null或者不是对象”,然后显示包含网格中所有日期的页面,以便这些项目不为空,但是是否还有其他我应该用来执行此功能的代码/格式?

还查看了 http://demos.telerik.com/aspnet-mvc/grid/customformatting 关于 .cellaction 如下所示

.CellAction(cell =>
{
    if (cell.Column.Title == "Title Name")
    {
        if (cell.DataItem.C1D > DateTime.Today.AddDays(183))
        {
            //Set the background of this cell only
            cell.HtmlAttributes["style"] = "background:red;";
        }
    }
})

,我必须将 .Name 更改为 .Title,因为它无法识别 .Name,但我收到错误消息“Error 1 Operator '>'”无法应用于“string”和“System.DateTime”类型的操作数”,因此看来我无法在单元格操作中执行这项复杂的任务。

我还在 telerik 论坛上发布了这个附加到另一个问题,但到目前为止还没有回复 http://www.telerik.com/community/forums/aspnet-mvc/grid/telerik-grid-row-custom-formatting-on-either-bit-int-string-field.aspx

编辑 3 -

附加控制器代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using (Database Name).Models;
using (Database Name).Models.DTO;
using Telerik.Web.Mvc;
using Telerik.Web.Mvc.UI;
namespace (Database Name).Controllers
{
    public class (Controller Name)Controller : Controller
{
(Database Name)Entities _db = new (Database Name)Entities();
public ActionResult List()
    {
        return View();
    }

现在就是这样,我已经没有什么可以提供的了,因为没有其他任何东西可能对 Telerik 网格产生任何影响,所以如果还有其他东西可能隐藏在其他地方,我可以可能会丢失,那么请解释一下可能是什么,因为我唯一没有包含的是与“创建”和“编辑”页面相关的代码,但它们涉及的只是制作每个简单的记录,然后允许用户更改记录的日期。

At least 3 ways I can think of that this could be done:-

1st (ideal) - in a single telerik grid which has around 8 columns, 1st col would list all table entries with the next 6 for displaying different dates submitted for each entry but not all necessarily having a value for each entry, final col would link to each entry on a separate page to allow new dates to be submitted via datepicker or to be edited.

Main problem is I need to be able to display each of the dates on the grid in different colours depending on each col, by this I mean I record a date in 1st col of which has a yearly renewal so if >6months then it's colour 1, >1month colour 2, <1month colour 3 and finally if past 1 year mark then colour 4.

There are also 2 different possible renewal lengths for the other col's.

2nd - Each different renewal length would get its own grid so 1st for 1y, 2nd for 2nd length and 3rd for 3rd length.

3rd (likely) - 4 grids to replace the colours it would simply display each category so 1 grid would show all entries which had more than 6months, grid 2 would show greater than 1month, grid 3 would show less than 1month and grid 4 would show past time length.

I have no clue how best to sort the dates out in a way that would do what I need it to but I figure either option 1 will be possible or option 3 is the simplest.

Edit -

using System
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace (...).Models.DTO
{
    public class ...DTO
    {
        public int Id { get; set; }
        public string Name { get; set; }
        //public string C1D
        //{
        //    get
        //    {
        //        if (C1D < DateTime.Today.AddDays(-183)) return "Green";
        //    }
        //}
        public string C1D
        {
            get
            {
                if ((C1D = DateTime.ParseExact(C1D, "yyyy/mm/dd", null)) < DateTime.Today.AddDays(-183)) return "Green";
            }
            set;
        }
        public string C2D { get; set; }

Here it shows how I have tried to setup C1D in 2 different ways and for C2D how I usually setup the cols which go into the telerik grid.

[GridAction]
    public ActionResult _List(int? Id)
    {
        List<...DTO> ret = new List<...DTO>();
        _db.(...).ToList().ForEach(x =>
        {
            ret.Add(new ...DTO
            {
                Id = x.Id,
                Name = x.(...)Name,
                C1D = (x.C1SD.HasValue) ? x.C1SD.Value.ToShortDateString() : "",
                C2D = (x.C2SD.HasValue) ? x.C2SD.Value.ToShortDateString() : "",

This is how I would go about setting it up in the controller for displaying the data in the telerik grid.

Below is how I setup the view

<% Html.Telerik().Grid<(...).Models.DTO.(...)DTO>()
   .Name("...List")
   .DataKeys(dk => dk.Add(x => x.Id))
   .Columns(c =>
       {
           c.Bound(x => x.Name);
           c.Bound(x => x.C1D)
               .Title("...");
           c.Bound(x => x.C2D)
               .Title("...");
           c.Bound(x => x.C3D)
               .Title("...");
           c.Bound(x => x.C4D)
               .Title("...");
           c.Bound(x => x.C5D)
               .Title("...");
           c.Bound(x => x.C6D)
               .Title("...");
           c.Bound(x => x.C7D)
               .Title("...");
       })
    .Sortable()
    .Filterable()
    .DataBinding(db => db.Ajax().Select("_List", "..."))
    .Render();
%>

Edit 2 -
I've also tried

.ClientEvents(e => e.OnDataBound("onDataBound"))

function onDataBound(e) {
    if (e.dataItem.C1D > DateTime.Today.AddDays(183)) {
        e.cell.style.backgroundColor = "green";
    }
    if (e.dataItem.C1D > DateTime.Today.AddDays(30)) {
        e.cell.style.backgroundColor = "orange";
    }
    if (e.dataItem.C1D > DateTime.Today) {
        e.cell.style.backgroundColor = "red";
    }
    if (e.dataItem.C1D <= DateTime.Today) {
        e.cell.style.backgroundColor = "purple";
    }

}

and upon reaching this page it would break into code and say "Microsoft JScript runtime error: 'dataItem.C1D' is null or not an object" and "Microsoft JScript runtime error: 'cell.style' is null or not an object" and then display the page with all the dates in the grid so those items aren't null but is there otherwise some other code/format I should be using to perform this function?

And also looked at http://demos.telerik.com/aspnet-mvc/grid/customformatting in regards to .cellaction like below

.CellAction(cell =>
{
    if (cell.Column.Title == "Title Name")
    {
        if (cell.DataItem.C1D > DateTime.Today.AddDays(183))
        {
            //Set the background of this cell only
            cell.HtmlAttributes["style"] = "background:red;";
        }
    }
})

and I had to change .Name to .Title since it didn't recognise .Name, but I get the error msg "Error 1 Operator '>' cannot be applied to operands of type 'string' and 'System.DateTime' " so seems I won't be able to perform this complex a task in a cell action.

I've also posted this on the telerik forums attached to another question but so far no reply
http://www.telerik.com/community/forums/aspnet-mvc/grid/telerik-grid-row-custom-formatting-on-either-bit-int-string-field.aspx

Edit 3 -

Additional Controller code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using (Database Name).Models;
using (Database Name).Models.DTO;
using Telerik.Web.Mvc;
using Telerik.Web.Mvc.UI;
namespace (Database Name).Controllers
{
    public class (Controller Name)Controller : Controller
{
(Database Name)Entities _db = new (Database Name)Entities();
public ActionResult List()
    {
        return View();
    }

That's it now there's nothing left which I can possibly provide since there's nothing else which could have any kind of affect on the telerik grid so if there is still something else which might be hidden some place else that I may be missing then please explain what that might be since the only thing I haven't included is the code to do with the Create and Edit pages but all they involve is making each simple record then allowing the user to change the dates recorded.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

删除会话 2024-10-28 13:48:42

编辑3:

当你这样做时:

当你这样做时 _db.(...).ToList().ForEach(x =>
{
ret.Add(新...DTO
{
Id = x.Id,
名称 = x.(...)名称,
C1D = (x.C1SD.HasValue) ? x.C1SD.Value.ToShortDateString() : "",
C2D = (x.C2SD.HasValue) ? x.C2SD.Value.ToShortDateString() : "",
}
x

将是 ObjectFromDB,您不想分配 DTO 的每个属性,您想传递 baseObject(巫师是 x),然后从 x 返回您想要的值。

如果您可以使用 putfile 或其他东西向我提供您的解决方案,如果您愿意,我可以看一下,但现在我不知道如何能够为您提供更多帮助...

End Edit 3

Can你放了一些代码吗?

我将采用解决方案 1。

您可以将 css 类添加到使用 ClientTemplate 中,如果它 > > [timespan],我认为您应该添加一个绑定在属性上的列,该属性可以根据时间跨度返回 css 类的名称或空字符串。假设您有一个 DateCol1 属性,它是一个 DateTime 您可以添加一个 DateCol1Css 属性,如下所示:

public string DateCol1Css
    {
        get
        {
            if(DateCol1 < DateTime.Now.AddMonths(-1)) return "Color1"; //witch is less than a month
            if(DateCol1 < DateTime.Now.AddMonths(-3)) return "Color2"; //witch is less than 3 months
            if(DateCol1 < DateTime.Now.AddMonths(-6)) return "Color3"; //witch is less than 6 months
            return  "";
        }
    }

    public string DateCol2Css
    {
        get
        {
            if (DateCol2 < DateTime.Now.AddDays(-10)) return "Color1"; //witch is less than 10 days
            if (DateCol2 < DateTime.Now.AddDays(-30)) return "Color2"; //witch is less than 30 days
            return "";
        }
    }

    public string DateCol3Css
    {
        get
        {
            if (DateCol3 < DateTime.Now.AddMonths(-1)) return "Color1"; //witch is less than a month
            if (DateCol3 < DateTime.Now.AddMonths(-3)) return "Color2"; //witch is less than 3 months
            if (DateCol3 < DateTime.Now.AddMonths(-6)) return "Color3"; //witch is less than 6 months
            return "";
        }
    }

网格应该如下所示:

    <%= Html.Telerik().Grid<SerializableAdmin>()
                        .Name("Grid")
                        .Columns(colums =>
                         {
                             colums.Bound(c => c.FirstName);
                             colums.Bound(c => c.Id);
                             colums.Bound(c => c.Id).ClientTemplate("<span class=\"<#=DateCol1Css#>\"<#=DateCol1#></span>");
colums.Bound(c => c.Id).ClientTemplate("<span class=\"<#=DateCol2Css#>\"<#=DateCol2#></span>");
colums.Bound(c => c.Id).ClientTemplate("<span class=\"<#=DateCol3Css#>\"<#=DateCol3#></span>");

                         })
                %>

编辑:

看一下这段代码,您传递了对象从数据库到新对象,并仅在 db 对象上使用 get 添加属性。

public class ObjectDTO
{
    public ObjectFromDB BaseObject { get; set; }

    public int Id 
    {
        get { return BaseObject.Id; }
    }

    public string Name 
    {
        get { return BaseObject.Name; }
    }


    public string C1D
    {
        get
        {
            if (BaseObject.C1SC.HasValue && BaseObject.C1SC < DateTime.Now.AddDays(-183)) return "Green";
            return string.Empty;
        }
    }

    public string C2D
    {
        get
        {
            if (BaseObject.C2SC.HasValue && BaseObject.C2SC < DateTime.Now.AddDays(-183)) return "Green";
            return string.Empty;
        }
    }
}
[GridAction]
public ActionResult _List(int? Id)
{
    List<ObjectDTO> ret = new List<ObjectDTO>();
    _db.GetObjectFromDB().ToList().ForEach(x =>
    {
        ret.Add(new ObjectDTO { ObjectFromDB = x } );
    });
}

Edit 3 :

When you do :

When you do _db.(...).ToList().ForEach(x =>
{
ret.Add(new ...DTO
{
Id = x.Id,
Name = x.(...)Name,
C1D = (x.C1SD.HasValue) ? x.C1SD.Value.ToShortDateString() : "",
C2D = (x.C2SD.HasValue) ? x.C2SD.Value.ToShortDateString() : "",
}
}

x would be the ObjectFromDB, you don't want to assign each properties of the DTO, you want to pass the baseObject (witch is x), then return the value you want from x.

If you can provide me with youre solution using putfile or something else I can take a look at it if you want to but right now I don't know how it would be possible to help you more than that...

End Edit 3

Can you put some code?

I'll go with solution 1.

You could add a css class to a using ClientTemplate, if it's > [timespan], I think that you should add a colum that is bound on a property that could return name of a css class or an empty string depending on the time span. Let say you have a DateCol1 property witch is a DateTime you could add a DateCol1Css property that goes like this :

public string DateCol1Css
    {
        get
        {
            if(DateCol1 < DateTime.Now.AddMonths(-1)) return "Color1"; //witch is less than a month
            if(DateCol1 < DateTime.Now.AddMonths(-3)) return "Color2"; //witch is less than 3 months
            if(DateCol1 < DateTime.Now.AddMonths(-6)) return "Color3"; //witch is less than 6 months
            return  "";
        }
    }

    public string DateCol2Css
    {
        get
        {
            if (DateCol2 < DateTime.Now.AddDays(-10)) return "Color1"; //witch is less than 10 days
            if (DateCol2 < DateTime.Now.AddDays(-30)) return "Color2"; //witch is less than 30 days
            return "";
        }
    }

    public string DateCol3Css
    {
        get
        {
            if (DateCol3 < DateTime.Now.AddMonths(-1)) return "Color1"; //witch is less than a month
            if (DateCol3 < DateTime.Now.AddMonths(-3)) return "Color2"; //witch is less than 3 months
            if (DateCol3 < DateTime.Now.AddMonths(-6)) return "Color3"; //witch is less than 6 months
            return "";
        }
    }

And the grid should be like this :

    <%= Html.Telerik().Grid<SerializableAdmin>()
                        .Name("Grid")
                        .Columns(colums =>
                         {
                             colums.Bound(c => c.FirstName);
                             colums.Bound(c => c.Id);
                             colums.Bound(c => c.Id).ClientTemplate("<span class=\"<#=DateCol1Css#>\"<#=DateCol1#></span>");
colums.Bound(c => c.Id).ClientTemplate("<span class=\"<#=DateCol2Css#>\"<#=DateCol2#></span>");
colums.Bound(c => c.Id).ClientTemplate("<span class=\"<#=DateCol3Css#>\"<#=DateCol3#></span>");

                         })
                %>

Edit :

Take a look at this code, you pass the object from the database to your new object and add property with get only on the db object.

public class ObjectDTO
{
    public ObjectFromDB BaseObject { get; set; }

    public int Id 
    {
        get { return BaseObject.Id; }
    }

    public string Name 
    {
        get { return BaseObject.Name; }
    }


    public string C1D
    {
        get
        {
            if (BaseObject.C1SC.HasValue && BaseObject.C1SC < DateTime.Now.AddDays(-183)) return "Green";
            return string.Empty;
        }
    }

    public string C2D
    {
        get
        {
            if (BaseObject.C2SC.HasValue && BaseObject.C2SC < DateTime.Now.AddDays(-183)) return "Green";
            return string.Empty;
        }
    }
}
[GridAction]
public ActionResult _List(int? Id)
{
    List<ObjectDTO> ret = new List<ObjectDTO>();
    _db.GetObjectFromDB().ToList().ForEach(x =>
    {
        ret.Add(new ObjectDTO { ObjectFromDB = x } );
    });
}
暮凉 2024-10-28 13:48:42

对于此代码块,您是否尝试将字符串转换为日期时间?

    .CellAction(cell =>
{
    if (cell.Column.Title == "Title Name")
    {
        if (!string.IsNullOrEmpty(cell.DataItem.C1D) && DateTime.ParseExact(cell.DataItem.C1D, "yyyy/mm/dd", null) > DateTime.Today.AddDays(183))
        {
            //Set the background of this cell only
            cell.HtmlAttributes["style"] = "background:red;";
        }
    }
})

你的 CssColor 的 ...Dto 属性应该是这样的:

public class ...DTO
{
        public int Id { get; set; }
        public string Name { get; set; }
        public string C1D
        {
            get
            {
                if (!C1SD.HasValue) return string.Empty;
                return (DateTime.ParseExact(C1SD, "yyyy/mm/dd", null) < DateTime.Today.AddDays(-183)) ? "Green" : "";
            }
        }
}

所以你的 GridAction 应该是这样的:

[GridAction]
    public ActionResult _List(int? Id)
    {
        List<...DTO> ret = _db.(...).ToList();
 ...

如果有帮助,请告诉我!

For this code block, have you try to cast the string in datetime?

    .CellAction(cell =>
{
    if (cell.Column.Title == "Title Name")
    {
        if (!string.IsNullOrEmpty(cell.DataItem.C1D) && DateTime.ParseExact(cell.DataItem.C1D, "yyyy/mm/dd", null) > DateTime.Today.AddDays(183))
        {
            //Set the background of this cell only
            cell.HtmlAttributes["style"] = "background:red;";
        }
    }
})

And your ...Dto property for the CssColor should be like this :

public class ...DTO
{
        public int Id { get; set; }
        public string Name { get; set; }
        public string C1D
        {
            get
            {
                if (!C1SD.HasValue) return string.Empty;
                return (DateTime.ParseExact(C1SD, "yyyy/mm/dd", null) < DateTime.Today.AddDays(-183)) ? "Green" : "";
            }
        }
}

So your GridAction would be like this :

[GridAction]
    public ActionResult _List(int? Id)
    {
        List<...DTO> ret = _db.(...).ToList();
 ...

Let me know if it helps!

我是男神闪亮亮 2024-10-28 13:48:42

这就是我从一开始就尝试做的事情,

[GridAction]
public ActionResult _List(int? Id)
{
    List<...DTO> ret = new List<...DTO>();
    _db.(...).ToList().ForEach(x =>
    {
        ret.Add(new ...DTO
        {
            Id = x.Id,
            Name = x.(...)Name,
            C1D = (x.C1SD.HasValue) ? x.C1SD.Value.ToShortDateString() : "",
            C2D = (x.C2SD.HasValue) ? x.C2SD.Value.ToShortDateString() : "",

技巧是在控制器中进行所有计算,并使模型和视图保持非常基本的状态。

模型 - 将它们全部保留为字符串,并且基本上执行了 public string blah { get; set;} 对于每个日期列,然后对于每个列,你想要做一些复杂的事情,比如我的日期计算,你会做一个额外的列,这将用于颜色/你想要的任何功能,你甚至可以设置一个管理功能,因此如果他们没有 win 身份验证或角色不正确等,那么它会破坏数据或取消链接 url 链接。

控制器 - 正如您在上面看到的,这就是我如何整理显示的日期,现在是整理颜色或 w/e 的令人惊讶的简单方法,(示例 blahDTO bdt = new blahDTO(); )

if (x.TestVal1 != null)
                {
                    if ((x.TestVal1) > (DateTime.Today.AddMonths(6)))
                    {
                        bdt.Colourflag1 = "green";
                    }

现在它不必是绿色的,它可以是 true false tom dick 或 jane w/e,但它只需是基于某些独特条件分配的值。

查看-当我意识到这可能这么容易时,我捂住了自己的脸,无论如何,所以 c.Bound(x => x.Colourflag1).Hidden(true); 下一步

.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
<script type="text/javascript">
   function onRowDataBound(e) {

           if (e.dataItem.TestVal1 == "green") {

               e.row.cells[1].style.backgroundColor = "green";
           }

,嘿,你只需转身第一行/列单元格为绿色,可以将其扭曲并用于 w/e e.row.cell[?]。可以用于,你有一个单元格可以完成所有魔法,耶哈滚成了 1。

现在我知道我的 jscript 代码是浪费的,因为我确信此时你可以使绿色成为一个对象,然后影响下一个对象,因此如果是黄色,那么它会使背景颜色代码适合黄色。

如果有人有任何问题或 jscript 建议,请随时提问/评论。

This was what I tried to do from the start

[GridAction]
public ActionResult _List(int? Id)
{
    List<...DTO> ret = new List<...DTO>();
    _db.(...).ToList().ForEach(x =>
    {
        ret.Add(new ...DTO
        {
            Id = x.Id,
            Name = x.(...)Name,
            C1D = (x.C1SD.HasValue) ? x.C1SD.Value.ToShortDateString() : "",
            C2D = (x.C2SD.HasValue) ? x.C2SD.Value.ToShortDateString() : "",

Trick is to do all the calculations in the controller and leave the model and view very basic.

Model- left em all as string and basically did public string blah { get; set;} for each date col and then for each col you want to do something complex like my date calculations you would make an additional col, this would be for the colour/whatever feature you want heck you could even setup an admin function so if they don't have win auth or aren't in correct role etc then it would splarf the data or de-link a url link.

Controller- well as you can see above thats how I sorted out the dates showing up and now the surprisingly simple way to sort out the colour or w/e, (example thing blahDTO bdt = new blahDTO(); )

if (x.TestVal1 != null)
                {
                    if ((x.TestVal1) > (DateTime.Today.AddMonths(6)))
                    {
                        bdt.Colourflag1 = "green";
                    }

Now it doesn't have to be green, it could be true false tom dick or jane w/e but it would just have to be a value assigned based on certain unique conditions.

View- when I realised it could be this easy I facepalmed myself, anyway yeh so c.Bound(x => x.Colourflag1).Hidden(true); next step

.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
<script type="text/javascript">
   function onRowDataBound(e) {

           if (e.dataItem.TestVal1 == "green") {

               e.row.cells[1].style.backgroundColor = "green";
           }

and hey presto you just turn the 1st row/col cell green and this can be twisted and used into w/e e.row.cell[?]. can be used for and you have a single cell do all magic ye ha rolled into 1.

Now I know my jscript code is wasteful since I'm sure at this point you could make the green be an object which would then affect the the next object so if yellow then it makes the background colour code fit in yellow.

If anybody has any questions or jscript advice feel free to ask/comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文