我的应用程序中有一个kendoGrid。我的问题是: 我的数据库中有一个0,但是当我在模板中使用kendo.tostring来表示kendoGrid时,他不会显示0.但是当我有0,2时,kendo.tostring会显示0,2。那么我怎样才能成功只显示0 ??
这是mys javascript代码:
$("#tab_intensite").kendoGrid({
dataSource:intensite_data,
scrollable: true,
sortable : true,
pageable : false,
detailInit: function(e){
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
data:intensite,
filter: { field: "idDepart", operator: "eq", value: e.data.idDepart }
},
columns: [
{ field: "intituledep", title: "DÉSIGNATION"}
]
});
},
editable: true,
height: 400,
change:function(){
console.log($this);
$this.attr("font-weight", "bold");
},
save: function() {
$("#tableau_saisie_intensite").data("kendoGrid").dataSource.update;
$("#tableau_saisie_intensite").data("kendoGrid").refresh();
$("#tableau_saisie_intensite").data("kendoGrid").dataSource.bind("change", function (e) {
setdatasourcessss();
});
},
columns: [
{ field: "cel", title: "DÉPART", width:50,headerAttributes: { style:"text-align: center;"} },
{ field: "date_releve", title: "Date Relevé", width:50, format: "{0:dd/MM/yyyy }" ,attributes: { style:"text-align: center;"},headerAttributes: { style:"text-align: center;"} ,
footerTemplate: "<div id='date_intensite_total' style='width:98%;position:relative;text-align: center;' ></div> "},
{ field: "n", title: "N", width:50, attributes: { style:"text-align: center;"},
footerTemplate: "#= kendo.toString(sum, 'n') # A", template:"#= (n) ? kendo.toString(n)+ ' A': ''# <span style='float: right;' class='k-icon k-edit'></span>", headerAttributes: { style:"text-align: center;"}},
{ field: "ph1", title: "PH1", width:50, attributes: { style:"text-align: center;"},
footerTemplate: "#= kendo.toString(sum, 'n') # A", template:"#= (ph1) ? kendo.toString(ph1, 'n')+ ' A': ''# <span style='float: right;' class='k-icon k-edit'></span>", headerAttributes: { style:"text-align: center;"}},
{ field: "ph2", title: "PH2", width:50, attributes: { style:"text-align: center;"},
footerTemplate: "#= kendo.toString(sum, 'n') # A", template:"#=(ph2) ?kendo.toString(ph2)+ ' A': ''# <span style='float: right;' class='k-icon k-edit'></span> ", headerAttributes: { style:"text-align: center;"}},
{ field: "ph3", title: "PH3", width:50, attributes: { style:"text-align: center;"},
footerTemplate: "#= kendo.toString(sum, 'n') # A", template:"#=(ph3) ?kendo.toString(ph3, 'n')+ ' A' : ''# <span style='float: right;' class='k-icon k-edit'></span>", headerAttributes: { style:"text-align: center;"}},
],
});
如果有人可以帮助我,那就太棒了!提前谢谢!!
答案 0 :(得分:0)
代码中的kendo.toString()
语句没有问题。您遇到的唯一问题是template
上的三元操作,请在第n
栏声明中查看您的代码,您可以在那里看到:
template: (n) ? kendo.toString(n)+ ' A': ''
因此当值0
时,''
将被采用,因为0
falsey 。将''
更改为'0'
,那么您的问题就会消失。
您必须修改template
,n
,ph1
和ph2
列的ph3
,以便像这样。
columns: [
....
{
field: "n",
template: "#= (n) ? kendo.toString(n)+ ' A': '0'# <span style='float: right;' class='k-icon k-edit'></span>",
...
},
{
field: "ph1",
template: "#= (ph1) ? kendo.toString(ph1, 'n')+ ' A': '0'# <span style='float: right;' class='k-icon k-edit'></span>",
...
},
{
field: "ph2",
template: "#=(ph2) ?kendo.toString(ph2)+ ' A': '0'# <span style='float: right;' class='k-icon k-edit'></span> ",
...
},
{
field: "ph3",
template: "#=(ph3) ?kendo.toString(ph3, 'n')+ ' A' : '0'# <span style='float: right;' class='k-icon k-edit'></span>",
...
},
],
以下是剪切完整修复程序,您可以运行它来查看结果。
var data = [{
"cel": "a",
"date_releve": "a",
"n": 0.2,
"ph1": 0,
"ph3": 0.2,
"ph2": 0.5
}]
$("#grid").kendoGrid({
dataSource: data,
scrollable: true,
sortable: true,
pageable: false,
detailInit: function(e) {
$("<div/>").appendTo(e.detailCell).kendoGrid({
dataSource: {
data: intensite,
filter: {
field: "idDepart",
operator: "eq",
value: e.data.idDepart
}
},
columns: [{
field: "intituledep",
title: "DÉSIGNATION"
}
]
});
},
editable: true,
height: 400,
change: function() {
console.log($this);
$this.attr("font-weight", "bold");
},
save: function() {
$("#tableau_saisie_intensite").data("kendoGrid").dataSource.update;
$("#tableau_saisie_intensite").data("kendoGrid").refresh();
$("#tableau_saisie_intensite").data("kendoGrid").dataSource.bind("change", function(e) {
setdatasourcessss();
});
},
columns: [
{
field: "cel",
title: "DÉPART",
width: 50,
headerAttributes: {
style: "text-align: center;"
}
},
{
field: "date_releve",
title: "Date Relevé",
width: 50,
format: "{0:dd/MM/yyyy }",
attributes: {
style: "text-align: center;"
},
headerAttributes: {
style: "text-align: center;"
},
footerTemplate: "<div id='date_intensite_total' style='width:98%;position:relative;text-align: center;' ></div> "
},
{
field: "n",
title: "N",
width: 50,
attributes: {
style: "text-align: center;"
},
footerTemplate: "#= kendo.toString(sum, 'n') # A",
template: "#= (n) ? kendo.toString(n)+ ' A': '0'# <span style='float: right;' class='k-icon k-edit'></span>",
headerAttributes: {
style: "text-align: center;"
}
},
{
field: "ph1",
title: "PH1",
width: 50,
attributes: {
style: "text-align: center;"
},
footerTemplate: "#= kendo.toString(sum, 'n') # A",
template: "#= (ph1) ? kendo.toString(ph1, 'n')+ ' A': '0'# <span style='float: right;' class='k-icon k-edit'></span>",
headerAttributes: {
style: "text-align: center;"
}
},
{
field: "ph2",
title: "PH2",
width: 50,
attributes: {
style: "text-align: center;"
},
footerTemplate: "#= kendo.toString(sum, 'n') # A",
template: "#=(ph2) ?kendo.toString(ph2)+ ' A': '0'# <span style='float: right;' class='k-icon k-edit'></span> ",
headerAttributes: {
style: "text-align: center;"
}
},
{
field: "ph3",
title: "PH3",
width: 50,
attributes: {
style: "text-align: center;"
},
footerTemplate: "#= kendo.toString(sum, 'n') # A",
template: "#=(ph3) ?kendo.toString(ph3, 'n')+ ' A' : '0'# <span style='float: right;' class='k-icon k-edit'></span>",
headerAttributes: {
style: "text-align: center;"
}
},
],
});
&#13;
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.common.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.rtl.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.default.min.css">
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2018.1.221/styles/kendo.mobile.all.min.css">
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.1.221/js/angular.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.1.221/js/jszip.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2018.1.221/js/kendo.all.min.js"></script>
<div id="grid"></div>
&#13;