这是我的演示: http://jsfiddle.net/6ozr348y/1/
$(document).ready(function() {
var grid = $("#grid").kendoGrid({
dataSource: {
data: [
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'}],
schema: {
model: {
fields: {
FileName: { type: "string" },
LastName: { type: "string" } }
}
},
sort: {
field: "FileName",
dir: "asc"
},
pageSize: 10
},
height: 500,
scrollable: true,
sortable: true,
selectable: true,
filterable: true,
pageable: true,
columns: [
{
field: "FileName",
title: "File Name"
},
{
field: "LastName",
title: "Last Name"
}
]
}).data("kendoGrid");
grid.tbody.parents(".k-grid-content").eq(0).kendoScroller({ useOnDesktop: false });
});
答案 0 :(得分:0)
这是DEMO。以下是代码:
<强> JS:强>
$(document).ready(function() {
var grid = $("#grid").kendoGrid({
dataSource: {
data: [
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'},
{ FileName: 'need to get the value from the text box', LastName: 'LastName'}],
schema: {
model: {
fields: {
FileName: { type: "string" },
LastName: { type: "string" } }
}
},
sort: {
field: "FileName",
dir: "asc"
},
pageSize: 10
},
height: 500,
scrollable: true,
//editable: true,
sortable: true,
selectable: true,
filterable: true,
pageable: true,
columns: [
{
field: "FileName",
title: "File Name"
},
{
field: "LastName",
title: "Last Name"
}
]
}).data("kendoGrid");
//grid.tbody.parents(".k-grid-content").eq(0).kendoScroller({ useOnDesktop: false });
$('#save').click(function(){
var fname = $('#fname').val();
//alert(fname);
var grid = $("#grid").data("kendoGrid");
var dataSource = grid.dataSource;
var total = dataSource.data().length;
dataSource.insert(total, {FileName:fname, LastName: 'Last Name'});
//grid.addRow({FileName: fname});
alert('New row added !!');
$('#fname').val('')
});
});
<强> HTML:强>
<h3>Enter filename in textbox and hit Save button. The new row with filename will be added to the grid</h3>
<input type="text" name="fname" id="fname" placeholder="Enter filename">
<button type="button" id="save">save</button>
<br>
<br>
<br>
<div id="grid"></div>