我想创建jqwidgets数据网格,我希望所有列都作为字符串,但是当我通过javascript而不是某些字符串值添加新行时,组件设置了我的数字0,1,2,3 ets ..
这是代码:
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;
}
检查urow的newrow函数我设置值&#34; Hallo&#34;但我得到0并且每下一行我都有增量值,这看起来像是计数还是?怎么解决这个?
答案 0 :(得分:1)
如果您不想要自动生成的ID,则需要设置源对象的id成员。