When I change the order of the items/rows in the grid using client side code, I would like to find the new order representation.
I used the MasterTableView.Items collection and I end up with the original order, as when I bind the grid with the data.
What is the correct collection property to iterate through to retrieve the current row order of the rearranged grid?
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
var _selectedRow;
function radgvAddress_RowSelected(sender, args) {
_selectedRow = $get(args.get_id());
}
function moveRowUp() {
if (_selectedRow && _selectedRow.sectionRowIndex > 0) {
swapRows(_selectedRow, _selectedRow.parentNode.rows[_selectedRow.sectionRowIndex - 1])
}
}
function moveRowDown() {
if (_selectedRow && _selectedRow.sectionRowIndex < _selectedRow.parentNode.rows.length - 1) {
swapRows(_selectedRow, _selectedRow.parentNode.rows[_selectedRow.sectionRowIndex + 1])
}
}
function serializeChanges(index1, index2) {
var reorderInput = document.getElementById("ReorderChanges");
if (reorderInput) {
reorderInput.value += index1 + "," + index2 + ";";
}
}
function swapRows(sourceRow, targetRow) {
for (var i = 0; i < sourceRow.cells.length; i++) {
var cellContent1 = targetRow.cells[i].innerHTML;
var cellContent2 = sourceRow.cells[i].innerHTML;
targetRow.cells[i].innerHTML = cellContent2;
sourceRow.cells[i].innerHTML = cellContent1;
}
$find("<%= radgvAddress.MasterTableView.ClientID %>").selectItem(targetRow);
serializeChanges(sourceRow.sectionRowIndex, targetRow.sectionRowIndex);
}
</script>
</telerik:RadScriptBlock>
//// I've used a foreach statement also but then I figured it was the collection. radgvAddress.MasterTableView.Items return the orginal order for us.
for (int i = radgvAddress.Items.Count; i > 0; i--)
{
//int PatientAddressID = Convert.ToInt32(radgvAddress.Items[i - 1].OwnerTableView.DataKeyValues[radgvAddress.Items[i - 1].ItemIndex]["PatientAddressID"]);
int PatientAddressID = Convert.ToInt32(radgvAddress.MasterTableView.Items[i - 1].GetDataKeyValue("PatientAddressID"));
QuickviewPMS_BO.PatientAddress PatientAddressObj = QuickviewPMS_BO.PatientAddress.GetPatientAddress(PatientAddressID, SessionHelper.SessionUserObjectsInfo.ClientId);
PatientAddressObj.AddressOrder = i;
if (!PatientAddressObj.IsValid)
{
GlobalHelper.ShowMessage(lblMessage, GlobalHelper.GetBrokenRules(PatientAddressObj), GlobalHelper.MessageType.Error);
return;
}
PatientAddressObj.Save();
}
radgvAddress.Rebind();
}