Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/429.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 自动生成剑道网格列时如何自定义列模板?_Javascript_Kendo Grid_Kendo Asp.net Mvc - Fatal编程技术网

Javascript 自动生成剑道网格列时如何自定义列模板?

Javascript 自动生成剑道网格列时如何自定义列模板?,javascript,kendo-grid,kendo-asp.net-mvc,Javascript,Kendo Grid,Kendo Asp.net Mvc,我使用javascript将数据源分配到剑道网格中: var dataSource = new kendo.data.DataSource({ transport: { read: { url: "@Url.Action("GetProductList", "Home")", type: "POST" } } });

我使用javascript将数据源分配到剑道网格中:

    var dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: "@Url.Action("GetProductList", "Home")",
                type: "POST"
            }
        }       
    });
    var grid = $("#gridHardwares").kendoGrid({
        dataSource: dataSource,
        height: 600,
        sortable: true,
        groupable: true,
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
        resizable: true
    }).data("kendoGrid");
请注意,datasource-column是动态生成的(它将每年扩展)

因此,我现在无法找到自定义列的方法。 我可以在这里做些什么来定制它,比如添加额外的复选框列、编辑页眉以及设置groupFooterTemplate

以前,列是固定的,我可以轻松自定义:

        columns: [
        {
            template: "<input type='checkbox' class='checkbox' />",
            width: 20
        }, {
            field: "PRODUCT_NAME",
            title: "Product Name",
            width: 200
        }, {
            field: "PRICE2017",
            title: "Price 2017",
            width: 200,
            aggregates: ["sum", "average"],
            groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
        }]
列:[
{
模板:“”,
宽度:20
}, {
字段:“产品名称”,
标题:“产品名称”,
宽度:200
}, {
字段:“价格2017”,
标题:“2017年价格”,
宽度:200,
合计:[“总和”、“平均值”],
groupFooterTemplate:“Sum:#=剑道.toString(Sum,'0.00')#|平均值:#=剑道.toString(平均值,'0.00')#”
}]
此外,是否可以在网格中编辑数据

如果使用javascript不是一个好主意,请告诉我:(
非常感谢您的任何建议或想法。提前感谢。

我在这里发布了我的解决方案,也许它可以帮助将来的人

    var customColumns =  [{
            template: "<input type='checkbox' class='checkbox' />",
            width: 20
        }];
var customColumns=[{
模板:“”,
宽度:20
}];
然后自定义您自己的标题:var customHeaders=[]

    for (var i = 0; i < customHeaders.length; i++) {
    if (i > 4) // after Name, Description, Region etc..
    {
        if (i == 5) // start with the first price column
        {
            customColumns.push({ 
                title : customHeaders[i], 
                field: headers[i],
                width: 150,
                template:
                    "# if(" + headers[i] + " != null) {# " +
                    "#= kendo.toString(" + headers[i] + ", 'n') #" +
                    "# } else { #" +
                    "" +
                    "#} # ",
                aggregates: ["sum", "average"],
                groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
            });
        }
        else // compare price with previous year
        {
            customColumns.push({ 
                title : customHeaders[i], 
                field: headers[i],
                width: 150,
                template:
                    "# if(" + headers[i] + " != null) {# " +
                    "#= calculatePercentage(" + headers[i-1] + ", " + headers[i] + ") #" +
                    "# } else { #" +
                    "" +
                    "#} # ",
                aggregates: ["sum", "average"],
                groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
            });
        }
    }
    else
    {
        customColumns.push({ 
            title : customHeaders[i], // customized header
            field: headers[i] // original header
        });
    }
}
for(var i=0;i4)//在名称、描述、区域等之后。。
{
if(i==5)//从第一个价格列开始
{
customColumns.push({
标题:自定义标题[i],
字段:标题[i],
宽度:150,
模板:
“#如果(“+头[i]+”!=null){#”+
“#=剑道.toString(“+headers[i]+”,'n')#”+
“}否则{”+
"" +
"#} # ",
合计:[“总和”、“平均值”],
groupFooterTemplate:“Sum:#=剑道.toString(Sum,'0.00')#|平均值:#=剑道.toString(平均值,'0.00')#”
});
}
else//将价格与上一年进行比较
{
customColumns.push({
标题:自定义标题[i],
字段:标题[i],
宽度:150,
模板:
“#如果(“+头[i]+”!=null){#”+
“#=计算百分比(“+headers[i-1]+”,“+headers[i]+”)#”+
“}否则{”+
"" +
"#} # ",
合计:[“总和”、“平均值”],
groupFooterTemplate:“Sum:#=剑道.toString(Sum,'0.00')#|平均值:#=剑道.toString(平均值,'0.00')#”
});
}
}
其他的
{
customColumns.push({
标题:CustomHeader[i],//自定义标题
字段:头[i]//原始头
});
}
}

谢谢你的提示!

我在这里发布了我的解决方案,也许它可以在将来帮助别人

    var customColumns =  [{
            template: "<input type='checkbox' class='checkbox' />",
            width: 20
        }];
var customColumns=[{
模板:“”,
宽度:20
}];
然后自定义您自己的标题:var customHeaders=[]

    for (var i = 0; i < customHeaders.length; i++) {
    if (i > 4) // after Name, Description, Region etc..
    {
        if (i == 5) // start with the first price column
        {
            customColumns.push({ 
                title : customHeaders[i], 
                field: headers[i],
                width: 150,
                template:
                    "# if(" + headers[i] + " != null) {# " +
                    "#= kendo.toString(" + headers[i] + ", 'n') #" +
                    "# } else { #" +
                    "" +
                    "#} # ",
                aggregates: ["sum", "average"],
                groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
            });
        }
        else // compare price with previous year
        {
            customColumns.push({ 
                title : customHeaders[i], 
                field: headers[i],
                width: 150,
                template:
                    "# if(" + headers[i] + " != null) {# " +
                    "#= calculatePercentage(" + headers[i-1] + ", " + headers[i] + ") #" +
                    "# } else { #" +
                    "" +
                    "#} # ",
                aggregates: ["sum", "average"],
                groupFooterTemplate: "Sum: #= kendo.toString(sum, '0.00') # || Average: #= kendo.toString(average, '0.00') #"
            });
        }
    }
    else
    {
        customColumns.push({ 
            title : customHeaders[i], // customized header
            field: headers[i] // original header
        });
    }
}
for(var i=0;i4)//在名称、描述、区域等之后。。
{
if(i==5)//从第一个价格列开始
{
customColumns.push({
标题:自定义标题[i],
字段:标题[i],
宽度:150,
模板:
“#如果(“+头[i]+”!=null){#”+
“#=剑道.toString(“+headers[i]+”,'n')#”+
“}否则{”+
"" +
"#} # ",
合计:[“总和”、“平均值”],
groupFooterTemplate:“Sum:#=剑道.toString(Sum,'0.00')#|平均值:#=剑道.toString(平均值,'0.00')#”
});
}
else//将价格与上一年进行比较
{
customColumns.push({
标题:自定义标题[i],
字段:标题[i],
宽度:150,
模板:
“#如果(“+头[i]+”!=null){#”+
“#=计算百分比(“+headers[i-1]+”,“+headers[i]+”)#”+
“}否则{”+
"" +
"#} # ",
合计:[“总和”、“平均值”],
groupFooterTemplate:“Sum:#=剑道.toString(Sum,'0.00')#|平均值:#=剑道.toString(平均值,'0.00')#”
});
}
}
其他的
{
customColumns.push({
标题:CustomHeader[i],//自定义标题
字段:头[i]//原始头
});
}
}

谢谢Sandman的提示!

将所有
price
对象保存在一个数组中(无论年份)都可以。剑道网格有很多,是的,Javascript是一个好主意,也是我首选的方法(尽管这很容易解释);更多地控制实体,更灵活。非常感谢!我想我现在知道该怎么做了!将所有
price
对象保存在一个数组中(无论年份)都可以。剑道网格有很多,是的Javascript是一个好主意,也是我的首选方法(尽管这很容易解释);更多地控制实体,更灵活。非常感谢!我想我现在知道该怎么办了!