EasyUI Forum
April 29, 2024, 04:50:47 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combogrid selectRow no longer working  (Read 7012 times)
bduguay
Newbie
*
Posts: 31


View Profile
« on: June 16, 2015, 12:41:12 PM »

I have upgraded from jQuery 1.11.0 to 2.13 and jQuery-EasyUI from 1.3.4 to 1.4.2 and I have now found that the selectRow for my combogrids is no longer working.

The issue is that the combogrid can have data with unique keys(1,2,3...) or all the same keys(they will all be '-1') and the title is the unique item.

If keyNumber='1' and keyName='Joe' it works.
If keyNumber='Joe' and keyName='Joe' it no longer works.
 
Here is my code.
Code:
	// Set the control name to a variable to eliminate the DOM lookups
var $control = $(conName);

$control.combogrid('setValue', keyNumber)
   .combogrid('grid').datagrid('selectRecord', keyNumber);
// If there isn't a row selected in the grid then just set the text in the box
if ($control.combogrid('grid').datagrid('getSelected') === null) {
$control.combogrid('setValue', keyNumber)
   .combogrid('setText', keyName);
// Scroll to the item in the grid
} else {
$control.combogrid('grid').datagrid('scrollTo', $control.combogrid('grid').datagrid('getRowIndex', keyNumber));
}

// If there is a no row selected then find the matching area in the grid and select it
if ($control.combogrid('grid').datagrid('getSelected') === null) {
// Get the data from the combogrid
var comboData = $control.combogrid('grid').datagrid('getData'),
found = false,
i = 0;
// Search through the comboData for the key
if (comboData) {
while ((i < comboData.total) && (!found)) {
if ((isNaN(keyNumber)) && (comboData.rows[i].title === keyNumber) || (comboData.rows[i].number === keyNumber)) {
found = true;
} else {
i++;
}
}
}
// If the key is found then select it in the combogrid
if (found) {
$control.combogrid('grid').datagrid('selectRow', i);
}
}


Any help would be appriciated.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: June 16, 2015, 05:10:53 PM »

Please refer to this example http://jsfiddle.net/xoq868cz/. It works fine.
Logged
bduguay
Newbie
*
Posts: 31


View Profile
« Reply #2 on: June 17, 2015, 07:54:47 AM »

Thank you for your response.

Yes your code works correctly but if I change the data to
Code:
   {number:'-1',title:'Joe1'},
   {number:'-1',title:'Joe2'},
   {number:'-1',title:'Joe3'}

and the code to
Code:
	var keyNumber = 'Joe2';
var keyName = 'Joe2';

it will still show 'Joe1' and not 'Joe2' as expected.
Logged
bduguay
Newbie
*
Posts: 31


View Profile
« Reply #3 on: June 19, 2015, 06:23:29 AM »

I have made a work around for the problem.

I set the idField for the combogrid based on if the field called 'number' contains data. If there is data in the field, set it as the idField, otherwise set the idField to a field called 'title'.

Code:
function setIdField(containsNumberField) {
    $('#controlName').combogrid({idField: containsNumberField ? 'number' : 'title'});
}

Thank you for your assistance.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!