JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://www.jeasyui.com/easyui/themes/default/easyui.css">
<script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<select id="cc" class="easyui-combogrid" style="width:250px" data-options="
panelWidth: 500,
idField: 'number',
textField: 'title',
data:[
{number:'1',title:'Joe'},
{number:'2',title:'Joe2'},
{number:'3',title:'Joe3'}
],
columns: [[
{field:'number',title:'Number',width:80},
{field:'title',title:'Title',width:120}
]],
fitColumns: true
">
</select>
JavaScript
var $control = $('#cc');
var keyNumber = 'Joe';
var keyName = 'Joe';
$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);
}
}