Search code examples
c#jqueryasp.net.netjqgrid

JqGrid add value on dropdown base on selected data on another jqgrid dropdown


Hi i'm currently stuck on the situation on jqgrid. example if i select sports the other dropdown will have a data of list of sports . i be able to load the data but i dont know how to start.

here's my code

$('#d1d2-lot-information-grid').jqGrid('clearGridData').trigger("reloadGrid");
    $('#d1d2-lot-information-grid').jqGrid({
        datatype: 'local',
        data: lots,
        editurl: 'clientArray',
        colNames: ['Device', 'Package', 'Lot No.', 'Lot Qty'],
        colModel: [
            { name: 'Device', index: 'Device', sortable: false, editable: true, editrules: { required: true }, edittype: 'select', },
            {
                name: 'Package',
                index: 'Package',
                sortable: false,
                editable: true,
                editrules: { required: true },
                edittype: 'select',
                editoptions: { value: packageOptions },
            },
            { name: 'LotNo', index: 'LotNo', sortable: false, editable: true, editrules: { required: true }, },
            { name: 'LotQty', index: 'LotQty', sortable: false, editable: true, editrules: { required: true }, }
        ],
        beforeSelectRow: function (id) {
            if ($('#' + id).attr('editable') == 1) {
                return false;
            }
        },
        pager: '#d1d2-lot-information-pager',
        pgbuttons: false,
        pginput: false,
        sortorder: 'asc',
        sortname: 'name',
        multiselect: true,
        height: '130',
        maxheight: '130',
        width: '522',
        viewrecords: true,
        rowNum: 10000
    });
    $('#d1d2-lot-information-grid').jqGrid({ recreateForm: true })

    // Disable form CRUD
    $('#d1d2-lot-information-grid').jqGrid('navGrid', '#d1d2-lot-information-pager', { edit: false, save: false, add: false, cancel: false, del: show, search: false, refresh: false });

    // Enable inline CRUD
    $('#d1d2-lot-information-grid').jqGrid('inlineNav', '#d1d2-lot-information-pager', { add: show, edit: show, save: show, cancel: show });
}

i kinda new at jqgrid sorry for my bad english hope you understand me it should work on inline add and inline edit


Solution

  • Solve my problem by this code . a bit messy but work as my need

     $('#d1d2-lot-information-grid').jqGrid({
            datatype: 'local',
            data: lots,
            editurl: 'clientArray',
            colNames: ['Device', 'Package', 'Lot No.', 'Lot Qty'],
            colModel: [
                { name: 'Device', index: 'Device', sortable: false, editable: true, editrules: { required: true }, edittype: 'select', editoptions:{value:':-Select Device-'} },
                {
                    name: 'Package',
                    index: 'Package',
                    sortable: false,
                    editable: true,
                    editrules: { required: true },
                    edittype: 'select',
                    editoptions: { value: packageOptions,dataEvents: [
                            {
                                type: 'change',
                                fn: function(e) {
    
                                var packageID = $(this).val();
    
                                 var selr = jQuery('#d1d2-lot-information-grid').jqGrid('getGridParam', 'selrow');
    
                                        var  modes = [],
                                          params = { packageID:packageID };
    
                                         $.ajax({
                                             async: false,
                                             type: 'POST',
                                             contentType: 'application/json',
                                             url: baseUrl + 'ncrb/Default.aspx/GetDevice',
                                             data: JSON.stringify(params),
                                             dataType: 'json',
                                            success: function (data) { modes = data; },
                                            error: function (xhr, status, error) { console.log(xhr, status, error); }
                                        });
                                        var targetrow = '#'+selr + '_Device';
    
                                        $(targetrow).empty();
                                        var items="";
    
                                             $.each(modes, function (key, value) {
    
                                                   items = '<option value="' + value.Description + '">' + value.Description + '</option>';
                                                       $(targetrow).append(items);
                                             });
    
    
                                         return modes;
    
    
                                }
                            }
                        ] },
    
                },
                { name: 'LotNo', index: 'LotNo', sortable: false, editable: true, editrules: { required: true }, },
                { name: 'LotQty', index: 'LotQty', sortable: false, editable: true, editrules: { required: true }, }
            ],
            beforeSelectRow: function (id) {
                if ($('#' + id).attr('editable') == 1) {
                    return false;
                }
            },
            pager: '#d1d2-lot-information-pager',
            pgbuttons: false,
            pginput: false,
            sortorder: 'asc',
            sortname: 'name',
            multiselect: true,
            height: '130',
            maxheight: '130',
            width: '522',
            viewrecords: true,
            rowNum: 10000
        });
        $('#d1d2-lot-information-grid').jqGrid({ recreateForm: true })
    
        // Disable form CRUD
        $('#d1d2-lot-information-grid').jqGrid('navGrid', '#d1d2-lot-information-pager', { edit: false, save: false, add: false, cancel: false, del: show, search: false, refresh: false });
    
        // Enable inline CRUD
        $('#d1d2-lot-information-grid').jqGrid('inlineNav', '#d1d2-lot-information-pager', { add: show, edit: show, save: show, cancel: show });