gpt4 book ai didi

javascript - 在 Kendo 网格列模板中添加计算

转载 作者:行者123 更新时间:2023-11-27 22:58:37 26 4
gpt4 key购买 nike

# if (((data.Price1 - data.Price2) / data.Price2< 0.02)) { #
<table class="bg-success">
<tr>
<td width="20px"><label title="Price1"></label></td>
<td width="90%">#= kendo.toString(Price1, 'n') || "0" #</td>
</tr>
<tr>
<td width="20px"><img title="Price2" /></td>
<td width="90%">#= kendo.toString(Price2, 'n') || "0" #</td>
</tr>
</table>
# } else { #
<table class="bg-danger">
<tr>
<td width="20px"><label title="Price1"></label></td>
<td width="90%">#= kendo.toString(Price1, 'n') || "0" #</td>
</tr>
<tr>
<td width="20px"><img title="Price2" /></td>
<td width="90%">#= kendo.toString(Price2, 'n') || "0" #</td>
</tr>
</table>
# } #

大家好,

上面是我添加的剑道列模板,但我收到无效模板错误,我假设这是由于我在 if 条件中添加的计算所致。我需要这个计算来进行列格式设置。请让我知道我在这里缺少什么或者我在这里出错的地方。提前致谢。

最佳答案

我尝试重现您的问题,但没有成功。我在下面分享了我的完整代码,因此请尝试使用它,如果有任何问题请告诉我。

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.mobile.all.min.css">

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.412/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.412/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.412/js/kendo.all.min.js"></script>
</head>
<body>
<div id="grid">
</div>
<script>
var products = [{
ProductID: 11,
ProductName: "Chai",
Price1: 13.0,
Price2: 11.0,
}, {
ProductID: 22,
ProductName: "Chang",
Price1: 19.0,
Price2: 11.0,
}, {
ProductID: 33,
ProductName: "Aniseed Syrup",
Price1: 1.0,
Price2: 11.0,
}, {
ProductID: 44,
ProductName: "Chef Anton's Cajun Seasoning",
Price1: 1.0,
Price2: 11.0,
}, {
ProductID: 55,
ProductName: "Chef Anton's Gumbo Mix",
Price1: 1.0,
Price2: 11.0,
}];
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: {
data: products,
schema: {
model: {
id: "ProductID",
fields: {
ProductName: {
type: "string"
}
},
}
},
pageSize: 10
},
sortable: true,
dataBound: function (e) {

},
filterable: true,
pageable: {
input: true,
numeric: false
},
columns: [
{ field: "ProductID", title: "ProductID" },
{ field: "ProductName", title: "ProductName" },
{
title: "Temp",
template: '# if (((Price1 - Price2) / Price2< 0.02)) { #' +
'<table class="bg-success">' +
'<tr>' +
'<td width="20px"><label title="Price1"></label></td>' +
'<td width="90%">#= kendo.toString(Price1, "n") || "0" #</td>' +
'</tr>' +
'<tr>' +
' <td width="20px"><img title="Price2" alt="Price2" /></td>' +
' <td width="90%">#= kendo.toString(Price2, "n") || "0" #</td>' +
'</tr>' +
'</table>' +
'# } else { # ' +
' <table class="bg-danger">' +
'<tr>' +
'<td width="20px"><label title="Price1"></label></td>' +
'<td width="90%">#= kendo.toString(Price1, "n") || "0" #</td>' +
'</tr>' +
'<tr>' +
'<td width="20px"><img title="Price2" /></td>' +
'<td width="90%">#= kendo.toString(Price2, "n") || "0" #</td>' +
'</tr>' +
'</table>' +
' # } # ',
},
{ command: ["edit", "destroy"], title: "&nbsp;" }

],
editable: "inline"
});
});

</script>
<style>
.bg-success {
background-color: green;
}

.bg-danger {
background-color: red;
}
</style>
</body>
</html>

编辑 1:对于列模板

<!DOCTYPE html>
<html>
<head>
<title>Jayesh Goyani</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.default.min.css">
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.1.412/styles/kendo.mobile.all.min.css">

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.412/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.412/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.412/js/kendo.all.min.js"></script>
</head>
<body>
<div id="grid">
</div>
<script type="text/x-kendo-template" id="priceColumnTemplate">
# if (((Price1 - Price2) / Price2< 0.02)) { #
<table class="bg-success">
<tr>
<td width="20px"><label title="Price1"></label></td>
<td width="90%">#= kendo.toString(Price1, "n") || "0" #</td>
</tr>
<tr>
<td width="20px"><img title="Price2" alt="Price2" /></td>
<td width="90%">#= kendo.toString(Price2, "n") || "0" #</td>
</tr>
</table>
# } else { #
<table class="bg-danger">
<tr>
<td width="20px"><label title="Price1"></label></td>
<td width="90%">#= kendo.toString(Price1, "n") || "0" #</td>
</tr>
<tr>
<td width="20px"><img title="Price2" /></td>
<td width="90%">#= kendo.toString(Price2, "n") || "0" #</td>
</tr>
</table>
# } #
</script>
<script>
var products = [{
ProductID: 11,
ProductName: "Chai",
Price1: 13.0,
Price2: 11.0,
}, {
ProductID: 22,
ProductName: "Chang",
Price1: 19.0,
Price2: 11.0,
}, {
ProductID: 33,
ProductName: "Aniseed Syrup",
Price1: 1.0,
Price2: 11.0,
}, {
ProductID: 44,
ProductName: "Chef Anton's Cajun Seasoning",
Price1: 1.0,
Price2: 11.0,
}, {
ProductID: 55,
ProductName: "Chef Anton's Gumbo Mix",
Price1: 1.0,
Price2: 11.0,
}];
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: {
data: products,
schema: {
model: {
id: "ProductID",
fields: {
ProductName: {
type: "string"
}
},
}
},
pageSize: 10
},
sortable: true,
dataBound: function (e) {

},
filterable: true,
pageable: {
input: true,
numeric: false
},
columns: [
{ field: "ProductID", title: "ProductID" },
{ field: "ProductName", title: "ProductName" },
{
title: "Temp",
template: kendo.template( $( '#priceColumnTemplate' ).html()),
},
{ command: ["edit", "destroy"], title: "&nbsp;" }

],
editable: "inline"
});
});

</script>
<style>
.bg-success {
background-color: green;
}

.bg-danger {
background-color: red;
}
</style>
</body>
</html>

关于javascript - 在 Kendo 网格列模板中添加计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37349825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com