【问题标题】:Dynamically Generated Telerik MVC3 Grid - Add Checkboxes动态生成 Telerik MVC3 网格 - 添加复选框
【发布时间】:2013-08-29 11:49:41
【问题描述】:

我有一个根据搜索条件动态生成的网格。我使用 Ajax 在局部视图中渲染网格。一切正常。

我现在需要添加一个复选框列作为第一列。

另外,我现在如何让过滤、排序分页等工作,因为它是在部分视图中。 当我单击标题进行排序时,我得到一个页面未找到错误并且过滤器图标没有做任何事情。

还有一件事。当我尝试将 GridCommandColumnSettings 添加到网格时出现错误 "无效的初始化成员声明器"

gridcolumnsettings 的代码如下

    public GridColumnSettings[] NewColumns(DataTable fullDT)
    {
        GridColumnSettings[] newColumns = new GridColumnSettings[fullDT.Columns.Count];

        for (int i = 0; i < fullDT.Columns.Count; i++)
        {
            // set the visibility property for the DeliveryID
            bool boolDeliveryID;
            if (fullDT.Columns[i].ColumnName == "DeliveryID")
                boolDeliveryID = false;
            else
                boolDeliveryID = true;

            newColumns[i] = new GridColumnSettings
            {
                new GridCommandColumnSettings
                {
                    Commands = 
                    {
                        new GridEditActionCommand(),
                        new GridDeleteActionCommand()
                    },
                    Width = "200px",
                    Title = "Commands"
                },
                Member = fullDT.Columns[i].ColumnName,
                Title = fullDT.Columns[i].ColumnName,
                Visible = boolDeliveryID,
                Filterable = true,
                Sortable = true
            };
        }
        return newColumns;
    }

任何建议将不胜感激。

谢谢

我编辑了我的帖子以添加我的部分网格

Here is my partial for the grid

@(Html.Telerik().Grid<System.Data.DataRow>(Model.Data.Rows.Cast<System.Data.DataRow>())
.Name("Grid")
.Columns(columns =>
{
    columns.LoadSettings(Model.Columns as IEnumerable<GridColumnSettings>);
})
.DataBinding(dataBinding =>       dataBinding.Ajax().Select("_DeliveryManagerCustomBinding", "Deliveries"))
.EnableCustomBinding(true)
 .Resizable(resize => resize.Columns(true))

)

【问题讨论】:

    标签: partial-views dynamic-data telerik-grid telerik-mvc


    【解决方案1】:

    当我使用 Telerik Grid 控件时,我不会以这种方式添加列,但看看你在做什么,我会冒险猜测你需要执行以下操作:

    将 newColumns 数组的大小增加 1(因为我们要在复选框列中添加):

    GridColumnSettings[] newColumns = new GridColumnSettings[fullDT.Columns.Count + 1];
    

    如果您希望在开始时使用它,则需要在 for 循环之前执行以下操作:

    GridColumnSettings s = new GridColumnSettings() {
      ClientTemplate("<input type=\"checkbox\"  name=\"checkeditems\" value=\"some value\" />")
      Title("title goes in here")
    };
    

    然后你将它添加到你的数组中:

    newColumns[0] = s;
    

    然后将 for 循环的起始索引增加到 1:

    for (int i = 1; i < fullDT.Columns.Count; i++)
    

    复选框列将放在开头

    【讨论】:

    • 我尝试了您的示例,当网格尝试渲染时,我得到以下结果。
    • 我对您的建议进行了更多修改,并使其发挥作用。感谢您的帮助...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多