This is a migrated thread and some comments may be shown as answers.

Retrieving the correct display order of a grid once modified via JavaScript.

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jared
Top achievements
Rank 1
Jared asked on 28 Oct 2010, 10:34 AM

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();

            }

1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 02 Nov 2010, 11:33 AM
Hi Aaron,

As you are using custom logic for moving the grid html up and down, you can try saving in a hidden field the new rows order and then use it on the server. Otherwise the grid items are in the order they are coming from its data source or the data source records sorted if sorting is applied for the grid.

Additionally, you can try using the built-in grid mechanism for items drag and drop and see if this works for you.

Kind regards,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Jared
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or