I'm working on the Codeigniter web application where I have used the jquery easyui Datagrid table, I have created the dropdown which is outside from the easyui Datagrid table, now how do I select dropdown value when Datagrid table is loaded?
Problem is that function is working but function selected all values from together from the dropdown, I need to select single dropdown value which is equal status value?
Datagrid Table
<table
id="tt"
class="easyui-datagrid"
url="<?php echo base_url()."contacts/contacts_list_data"; ?>"
pagination="true"
rownumbers="true"
toolbar="#tb"
pageSize="10"
pageList="[5,10,20,50,100]"
fit= "true"
fitColumns= "true"
nowrap= "true"
view= "detailview"
idField="id"
>
<thead>
<tr>
<th field="id" checkbox="true"></th>
<th field="status" sortable="true"><?php echo $this->lang->line('Status'); ?></th>
<th field="status_type" formatter='status_column'><?php echo $this->lang->line('Status'); ?></th>
</tr>
</thead>
</table>
Dropdown which is outside datagrid table
<script>
function status_column(value,row,index)
{
var inputVal = document.getElementById("status_column").innerHTML;
return inputVal;
}
</script>
<div id="status_column" style="display:none">
<select name="stat_column" id="stat_column" class="form_control stat_column">
<option value="">Select Status</option>
<option value='All'>All</option>
<option value='Open'>Open</option>
<option value='Closed'>Closed</option>
<option value='Won'>Won</option>
<option value='Lost Price is High'>Lost Price is High</option>
<option value='Lost Not Enough Features'>Lost Not Enough Features</option>
<option value='Lost Other'>Lost Other</option>
<option value='Never Replied Back'>Never Replied Back</option>
<option value='Bad Email'>Bad Email</option>
<option value='Bad Number'>Bad Number</option>
<option value='Do Not Disturb'>Do Not Disturb</option>
</select>
</div>
function to get dropdown values select based on the datagrid table column values
<script>
var selected=[];
$(function () {
$('#tt').datagrid({
onLoadSuccess:function(index, row ){
var rows = $('#tt').datagrid('getRows');
if(rows){
$.each(rows, function( index, row ) {
console.log(row+index)
selected.push(row.status)
})
console.log(userstatus);
$('#stat_column option[value="' + selected + '"]', row).attr('selected', 'selected');
}
}
});
})
</script>
Here the screenshots of the table and console


You can use
indexvalue to get thetrwhere you need to set selected value then use.find()to find your select-box inside that tr and use.propto set selected option.Demo Code :