gpt4 book ai didi

javascript - jqwidgets 数据网格计数

转载 作者:行者123 更新时间:2023-12-03 12:43:19 26 4
gpt4 key购买 nike

我想创建 jqwidgets 数据网格,我希望所有列都作为字符串,但是当我通过 javascript 添加新行而不是某些字符串值时,组件将我设置为数字 0,1,2,3 等..

这里是代码:

var source ={
datatype: "json",
cache:false,
contentType: 'application/json; charset=utf-8',
datafields: [
{ name: 'uid', type:'string'},
<%
int count = 1;
for(String col : us.columns) {

if(count == us.columns.length) {
%>
{ name: '<%= col %>' }
<%
}
else {
%>
{ name: '<%= col %>' },
<%
}
++count;
}
%>
],
url:"<%= request.getContextPath() %>/test/list/",
addrow: function (rowid, rowdata, position, commit) {


//alert(rowdata.uid +" "+ rowdata.ime);
//alert($.param(rowdata));
$.ajax({

url: "<%= request.getContextPath() %>/test/add/",
type: "POST",
data: $.param(rowdata),
success: function(data) {
//alert(data.error + " " + data.result + " " + data.mess);
alert(data.ime + " " + data.columns);
$("#historygrid").jqxGrid('updatebounddata');
increment++;
commit(true);
},
error:function(data) {

alert(data);
commit(false);
}
});

},
deleterow: function (rowid, commit) {

//commit(true);
}

};

var dataAdapter = new $.jqx.dataAdapter(source);

$("#testgrid").jqxGrid({
width: 659,
height: 300,
source: dataAdapter,
theme: 'office',
editable: true,
selectionmode: 'singlecell',
autoheight: false,
altrows: false,
showtoolbar: true,
rendertoolbar: function (toolbar) {
var me = this;
var container = $("<div style='margin: 5px;'></div>");
toolbar.append(container);
container.append('<input id="addrowbutton" type="button" value="Dodaj novi red" />');
container.append('<input style="margin-left: 5px;" id="deleterowbutton" type="button" value="Obrisi oznaceni red" />');
//container.append('<input style="margin-left: 5px;" id="updaterowbutton" type="button" value="Update Selected Row" />');

$("#addrowbutton").jqxButton();
$("#deleterowbutton").jqxButton();

// create new row.
$("#addrowbutton").on('click', function () {
var datarow = newrow();
var commit = $("#testgrid").jqxGrid('addrow', null, datarow);
});

// delete row.
$("#deleterowbutton").on('click', function () {
var selectedrowindex = $("#testgrid").jqxGrid('getselectedrowindex');
var rowscount = $("#testgrid").jqxGrid('getdatainformation').rowscount;
if (selectedrowindex >= 0 && selectedrowindex < rowscount) {
var id = $("#testgrid").jqxGrid('getrowid', selectedrowindex);
var commit = $("#testgrid").jqxGrid('deleterow', id);
}
});
},

columns: [
{ text: 'UID', datafield: 'uid', editable:false, width: '10%'},

<%

count = 1;
for(String col : us.columns) {

if(count == us.columns.length) {
%>
{ text:'<%= col %>', datafield: '<%= col %>', width: '45%'}
<%
}
else {
%>
{ text:'<%= col %>', datafield: '<%= col %>', width: '45%'},
<%
}
++count;
}
%>
]
});

var newrow = function (i) {
var row = {};
row["uid"] = "hallo";
<%
for(String col : us.columns) {
%>
row["<%=col%>"] = "Default Value";
<%
}
%>
return row;
}

检查 uid 的 newrow 函数,我设置了值“Hallo”,但我得到了 0 和 fo,我得到了增量值,这看起来像计数还是?怎么解决这个问题?

最佳答案

如果您不需要自动生成的 id,则需要设置源对象的 id 成员。

关于javascript - jqwidgets 数据网格计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23448912/

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