EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: 2plus2 on May 16, 2013, 09:49:32 AM



Title: Selecting Rows after Merging Cells....
Post by: 2plus2 on May 16, 2013, 09:49:32 AM
Howdy...

I have a data grid where I've merged the first two cells, and have "3" rows extending from those merged cells. (see attached image)

I'm carrying extra data with each row to populate a form, so when we "edit" the row - I'm trying to iterate through the "3" rows collecting the data I want.

Code:
    function updateDlg(rowIndex) {
        for (x = rowIndex; x <= rowIndex + 2; x++) {
            $('#dgAccounts').datagrid('selectRow', x);
            var row = $('#dgAccounts').datagrid('getSelected');
            var type = row.ThresholdTypeName;

            if (row.isInitiator == 'Yes') {
                $('#' + type + 'IsInitiator').combobox('setValue', '1');
                $('#' + type + 'InitiatorDetail').slideDown();
                $('#' + type + 'InitiatorThreshold').combobox('setValue', row.InitiatorThresholdId);
            }
            if (row.isApprover == 'Yes') {
                $('#' + type + 'IsApprover').combobox('setValue', '1');
                $('#' + type + 'ApproverDetail').slideDown();
                $('#' + type + 'ApproverThreshold').combobox('setValue', row.ApproverThresholdId);
            }
            if (row.isReleaser == 'Yes') {
                $('#' + type + 'Releaser').combobox('setValue', '1');
            }
        }
    }

However, when I try to select rows "#2", and "#3", I only get the first row returned. Is there anyway to select the other two rows if the first cells are merged?


Title: Re: Selecting Rows after Merging Cells....
Post by: stworthy on May 16, 2013, 06:38:49 PM
A more better way to get rows is calling 'getRows' method, please try code below:
Code:
var rows = $('#dgAccounts').datagrid('getRows');
for(var x = rowIndex; x<=rowIndex+2; x++){
  var row = rows[x];  // the row data
  console.log(row)
}


Title: Re: Selecting Rows after Merging Cells....
Post by: 2plus2 on May 16, 2013, 06:47:46 PM
But I only want the "selected" row and it's two "siblings". Seems like a waste to grab them all, look for the selected row, and the next two that I really want.


Title: Re: Selecting Rows after Merging Cells....
Post by: stworthy on May 16, 2013, 07:54:31 PM
Try code below:
Code:
var dg = $('#dgAccounts');
var selected = dg.datagrid('getSelected');  // the selected row
var rowIndex = dg.datagrid('getRowIndex', selected);  // the selected row index
var rows = dg.datagrid('getRows');
for(var x = rowIndex; x<=rowIndex+2; x++){
  var row = rows[x];  // the row data
  console.log(row)
}


Title: Re: Selecting Rows after Merging Cells....
Post by: 2plus2 on May 16, 2013, 08:40:36 PM
Thanks - that's where I ended up.

Probably not "fixable" but merging the cells plays havoc with some for the datagrid methods. Hope that gets a look at to see if there are more direct ways to get the row data.