我当前的任务是当用户单击该行中的按钮时,在 2 个 Kendo Ui 网格之间移动数据行。我有实际工作的代码,但我不明白为什么,希望有人能解释一下。我也想知道是否有更好的方法或一种有意义的方法来完成这项任务。环境为 Winsows 7、VS2012、MVC4、Kendo UI、jquery 1.8。我不明白的部分是 moveTo 函数。以 var row = $(elem.currentTarget).closest("tr"); 开头的部分 整个 toDS.add(..类似于下面注释的内容,但这不起作用。
其他需要注意的事项。我见过http://jsfiddle.net/OnaBai/2qXKy/ 但客户不想在网格中使用选择,他们想要单独的按钮。我还查看了http: //www.kendoui.com/forums/ui/grid/get-row-id-from-grid-when-custom-command-button-is-clicked.aspx 。这就是我得到注释掉代码部分的想法的地方。我可以让这更容易吗?谢谢
这是视图:
@model IEnumerable<AmWins.AL.GB.Web.ViewModels.BillingGroupPersonViewModel>
<h2>Add People</h2>
<div id="plan-entry" class="batchEntryContainer">
<div id="availableBillingGroupPeopleGrid"></div>
<div class="clear" />
<br />
<div id="addBillingGroupPeopleGrid"></div>
<div class="clear" />
</div>
<script type="text/javascript">
$(document).ready(function () {
var $availableBillingGroupPeopleGrid = $('#availableBillingGroupPeopleGrid').kendoGrid({
columns: [
// Match field names to AmWins.AL.GB.Web.ViewModels.BillingGroupPersonViewModel properties
{ command: { text: "push me", click: copySelectedToAddBillingGroupPeopleGrid, class: "action-column" }, title: " ", headerTemplate: '<button type="button" id="moveAllDown">Click Me!</button>', width: 50 },
{ field: "LastNameFirst", title: "Name" },
{ field: "EffectiveDate" },
{ field: "Status" },
{ field: "PersonId", title: "Person ID" },
{ field: "RelationshipType", title: "Type" },
{ field: "SSN" },
{ field: "StreetAddress", title: "Address" },
{ field: "City" },
{ field: "State" },
{ field: "Zip" }
],
editable: false,
scrollable: false,
dataSource: {}
});
@foreach (var person in Model) {
<text>
var $getGrid = $("#availableBillingGroupPeopleGrid").data("kendoGrid");
$getGrid.dataSource.add({
LastNameFirst: '@person.LastNameFirst',
EffectiveDate: '@person.EffectiveDate',
Status: '@person.Status',
PersonId: '@person.PersonId',
RelationshipType: '@person.RelationshipType',
SSN: '@person.SSN',
StreetAddress: '@person.StreetAddress',
City: '@person.City',
State: '@person.State',
Zip: '@person.Zip'
});
</text>
}
var $addBillingGroupPeopleGrid = $('#addBillingGroupPeopleGrid').kendoGrid({
columns: [
// Match field names to AmWins.AL.GB.Web.ViewModels.BillingGroupPersonViewModel properties
{ command: { text: "push me", click: copySelectedToAvailableBillingGroupPeopleGrid, class: "action-column" }, title: " ", headerTemplate: '<button type="button" id="moveAllUp">Click Me!</button>', width: 50 },
{ field: "LastNameFirst", title: "Name" },
{ field: "EffectiveDate" },
{ field: "Status" },
{ field: "PersonId", title: "Person ID" },
{ field: "RelationshipType", title: "Type" },
{ field: "SSN" },
{ field: "StreetAddress", title: "Address" },
{ field: "City" },
{ field: "State" },
{ field: "Zip" }
],
editable: false,
scrollable: false,
dataSource: {},
loadeddata: onloadeddata
});
function copySelectedToAddBillingGroupPeopleGrid(elem)
{
moveTo("down", elem);
}
function copySelectedToAvailableBillingGroupPeopleGrid(elem)
{
moveTo("up", elem);
}
function moveTo(direction, elem)
{
var fromGrid;
var fromDS;
var toDS;
if(direction == "down")
{
fromGrid = $("#availableBillingGroupPeopleGrid").data("kendoGrid");
fromDS = $("#availableBillingGroupPeopleGrid").data("kendoGrid").dataSource;
toDS = $("#addBillingGroupPeopleGrid").data("kendoGrid").dataSource;
}
else
{
fromGrid = $("#addBillingGroupPeopleGrid").data("kendoGrid");
fromDS = $("#addBillingGroupPeopleGrid").data("kendoGrid").dataSource;
toDS = $("#availableBillingGroupPeopleGrid").data("kendoGrid").dataSource;
}
var row = $(elem.currentTarget).closest("tr");
row.each(function () {
var dataItem = fromGrid.dataItem($(this));
toDS.add(
{
LastNameFirst: dataItem.LastNameFirst,
EffectiveDate: dataItem.EffectiveDate,
Status: dataItem.Status,
PersonId: dataItem.PersonId,
RelationshipType: dataItem.RelationshipType,
SSN: dataItem.SSN,
StreetAddress: dataItem.StreetAddress,
City: dataItem.City,
State: dataItem.State,
Zip: dataItem.Zip
});
});
fromGrid.removeRow($(elem.currentTarget).closest("tr"));
// This code only adds the pushbutton in the first column, not the entire row contents.
//var uid = $(this).parent().parent().attr('data-uid');
//var dataRow = fromDS.getByUid(uid);
//var dataItem = fromGrid.dataItem($(dataRow));
//toDS.add(dataItem);
}
function onloadeddata()
{
$("#move-all-up").click(moveAllUp);
$("#move-all-down").click(moveAllDown);
}
function moveAllUp()
{
}
function moveAllDown()
{
copySelectedToAddBillingGroupPeopleGrid($(this));
}
});
</script>