English 中文(简体)
是否有可能改变jqGrid s edit型:“选择”的沉积价值?
原标题:Is it possible to change the editoptions value of jqGrid s edittype:"select"?

我正在使用jqGrid 3.8.1。 我想根据另一 com子的选定价值,改变 com子的拉动价值。 因此,我正在探讨如何修改<代码>编辑: of an edittype:"select”

Here s the sample jqGrid code:

<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<script type="text/javascript" src="<c:url value="/js/jquery/grid.locale-ja.js" />" charset="UTF-8"></script>
<link type="text/css" rel="stylesheet" href="<c:url value="/css/jquery/ui.jqgrid.css" />"/>
<script src="<c:url value="/js/jquery/jquery.jqGrid.min.js" />" type="text/javascript"></script>
<table id="rowed5"></table>
<script type="text/javascript" charset="utf-8">
var lastsel2;
$("#rowed5").jqGrid({
    datatype: "local",
    height: 250,
    colNames:[ ID Number , Name ,  Stock ,  Ship via , Notes ],
    colModel:[
        {name: id ,index: id , width:90, sorttype:"int", editable: true},
        {name: name ,index: name , width:150,editable: true,editoptions:{size:"20",maxlength:"30"}},
        {name: stock ,index: stock , width:60, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
        {name: ship ,index: ship , width:90, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX;AR1:ARAMEX123456789"}},       
        {name: note ,index: note , width:200, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}}      
    ],
    caption: "Input Types",
    resizeStop: function (newwidth, index) {
        var selectedRowId = $("#rowed5").getGridParam( selrow );
        if(selectedRowId) {
            //resize combobox proportionate to column size
            var selectElement = $( [id="  + selectedRowId +  _ship"][role="select"] );
            if(selectElement.length > 0){
                $(selectElement).width(newwidth);
            }
        }
    }
    ,
    onSelectRow: function(id){
        if(id && id!==lastsel2){
            //$(this).saveRow(lastsel2, true);
            $(this).restoreRow(lastsel2);
            $(this).editRow(id,true);

            lastsel2=id;

            $(this).scroll();

            //resize combobox proportionate to column size
            var rowSelectElements = $( [id^="  + id +  _"][role="select"] );
            if(rowSelectElements.length > 0) {
                $(rowSelectElements).each(function(index, element){
                    var name = $(element).attr( name );
                    var columnElement = $( #rowed5_  + name);
                    if(columnElement.length > 0) {
                        var columnWidth = $(columnElement).width();
                        $(element).width(columnWidth);
                    }
                });
            }
        }
    }
});
var mydata2 = [
        {id:"12345",name:"Desktop Computer",note:"note",stock:"Yes",ship:"FedEx"},
        {id:"23456",name:"Laptop",note:"Long text ",stock:"Yes",ship:"InTime"},
        {id:"34567",name:"LCD Monitor",note:"note3",stock:"Yes",ship:"TNT"},
        {id:"45678",name:"Speakers",note:"note",stock:"No",ship:"ARAMEX123456789"},
        {id:"56789",name:"Laser Printer",note:"note2",stock:"Yes",ship:"FedEx"},
        {id:"67890",name:"Play Station",note:"note3",stock:"No", ship:"FedEx"},
        {id:"76543",name:"Mobile Telephone",note:"note",stock:"Yes",ship:"ARAMEX"},
        {id:"87654",name:"Server",note:"note2",stock:"Yes",ship:"TNT"},
        {id:"98765",name:"Matrix Printer",note:"note3",stock:"No", ship:"FedEx"}
        ];
for(var i=0;i < mydata2.length;i++) {
 $("#rowed5").jqGrid( addRowData ,mydata2[i].id,mydata2[i]);
}
</script>

Scenario:

  1. All ship will be displayed as initial load.
  2. If the stock column changes to Yes, ship will display only FedEx, TNT.
  3. If the stock column changes to No, ship will display only InTime, ARAMEX, ARAMEX123456789.

How can I change the options?

最佳回答

I solved it by trial and error. Want to share it, please refer to the below snippet. The changes are on onSelectRow function.

    onSelectRow: function(id){
    if(id && id!==lastsel2){
        //$(this).saveRow(lastsel2, true);
        $(this).restoreRow(lastsel2);

        // get the selected stock column value before the editRow
        var stockValue = $("#rowed5").jqGrid( getCell , id,  stock );
        if( stockValue ==  Yes ) {
            $("#rowed5").jqGrid( setColProp ,  ship , { editoptions: { value:  FE:FedEx;TN:TNT } });
        } else if( stockValue ==  No ) {
            $("#rowed5").jqGrid( setColProp ,  ship , { editoptions: { value:  IN:InTime;AR:ARAMEX;AR1:ARAMEX123456789 } });
        }

        $(this).editRow(id,true);

        lastsel2=id;

        $(this).scroll();

        //resize combobox proportionate to column size
        var rowSelectElements = $( [id^="  + id +  _"][role="select"] );
        if(rowSelectElements.length > 0) {
            $(rowSelectElements).each(function(index, element){
                var name = $(element).attr( name );
                var columnElement = $( #rowed5_  + name);
                if(columnElement.length > 0) {
                    var columnWidth = $(columnElement).width();
                    $(element).width(columnWidth);
                }
            });
        }
    }
}
问题回答

暂无回答




相关问题
selecting a row of data in sql for comparison

I have a set of string & numbers that I d like to use between databases. the idea is that table A has a row of data with 2 values acting as a single primary key Table B has the same 2 values of ...

bug when prototype and jQuery are both loaded

I have function in Javascript which works fine using prototype. The function is used to dynamicaly change a select field based on the selection of another field. var sizes_286 = new Array(); ...

problem with mutating tables

I want to create trigger which will be fired after insert into some table, let`s say user. In this trigger I want to select some records from table user, besides this one I insert to table, but then I ...

get data from gridview without querying database

I am new at this so please bear with me... I have managed to get the following code to work...so when I click on the "select" link in each row of the gridview, the data is transfered to other label/...

What can cause select to block in Python?

Here s a snippet of code I m using in a loop: while True: print loop rlist, wlist, xlist = select.select(readers, [], [], TIMEOUT) print selected # do stuff At a certain point, ...

Select statement performance

I m having a performance issue with a select statement I m executing. Here it is: SELECT Material.* FROM Material INNER JOIN LineInfo ON Material.LineInfoCtr = LineInfo.ctr INNER JOIN ...

热门标签