<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>How to filter subcategory dropdown list based on another category dropdown</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/themes/redmond/jquery-ui.css" />
    <link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/css/ui.jqgrid.css" />
    <!--<link rel="stylesheet" type="text/css" href="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/css/ui.jqgrid.css" />-->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>
    <!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>-->
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.js"></script>
    <!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>-->
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/i18n/grid.locale-en.js"></script>

    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.base.js"></script>
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.common.js"></script>
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.inlinedit.js"></script>
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/grid.custom.js"></script>
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/src/jquery.fmatter.js"></script>
    
    <!--http://www.ok-soft-gmbh.com/jqGrid/DependendSelects1.htm-->
    
    <!--<script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/js/i18n/grid.locale-en.js"></script>
    <script type="text/javascript" src="http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-3.8.2/js/jquery.jqGrid.min.js"></script>-->
    <script type="text/javascript">
    //<![CDATA[
        jQuery(document).ready(function () {
            var country = [{ConID : '1', ConName:'US'}, {ConID : '2', ConName : 'UK'}];
            var states = { '1': 'Alabama', '2': 'California', '3': 'Florida', '4': 'Hawaii', '5': 'London', '6': 'Oxford' };
            var statesOfCountry = {
                1: { '1': 'Alabama', '2': 'California', '3': 'Florida', '4': 'Hawaii' },
                2: { '5': 'London', '6': 'Oxford' }
            };
            var mydata = [
                { id: '0', Country: '1', State: '1', Name: "Louise Fletcher" },
                { id: '1', Country: '1', State: '3', Name: "Jim Morrison" },
                { id: '2', Country: '2', State: '5', Name: "Sherlock Holmes" },
                { id: '3', Country: '2', State: '6', Name: "Oscar Wilde" }
            ];
        var countries = '';
        for(var i = 0; i < country.length; i++)
        {//alert(country[i].ConID);
          countries += country[i].ConID +":" + country[i].ConName + ";";
        }
        countries = countries.slice(0,-1);
            var lastSel = -1;
            var grid = jQuery("#list");
            var resetStatesValues = function () {
                grid.setColProp('State', { editoptions: { value: states} });
            };
            grid.jqGrid({
                data: mydata,
                datatype: 'local',
                colModel: [
                    { name: 'Name', width: 200 },
                    { name: 'Country', width: 100, editable: true, formatter: 'select',
                        edittype: 'select', editoptions: {value: countries}
                    },
                ],
                onSelectRow: function (id) {
                    if (id && id !== lastSel) {
                        if (lastSel != -1) {
                            //grid.setColProp('State', { editoptions: { value: states} });
                            resetStatesValues();
                            grid.restoreRow(lastSel);
                        }
                        lastSel = id;
                    }
                },
                ondblClickRow: function (id, ri, ci) {
                    if (id && id !== lastSel) {
                        grid.restoreRow(lastSel);
                        lastSel = id;
                    }
                    //grid.setColProp('State', { editoptions: { value: states} });
                    resetStatesValues();
                    grid.editRow(id, true, null, null, 'clientArray', null,
                                 function (rowid, response) {  // aftersavefunc
                                     grid.setColProp('State', { editoptions: { value: states} });
                                 });
                    return;
                },
                editurl: 'clientArray',
                sortname: 'Name',
                height: '100%',
                viewrecords: true,
                rownumbers: true,
                sortorder: "desc",
                pager: '#pager',
                caption: "Demonstrate dependend select/dropdown lists (edit on double-click)"
            }); //.navGrid('#pager', { edit: false, add: false, del: false, search: false, refresh: false });
        });
    //]]>
    </script>
</head>

<body>
<table id="list"></table>
<div id="pager"></div>

</body>
</html>
// Code goes here

/* Styles go here */