Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

jquery - jqGrid: Editable column that always shows a select

Is there a way in jqgrid to have an editable column that uses a select like in this colModel example:

{ 
name: 'Options', 
index: 'Options', 
width: 150, 
align: 'left', 
resizable: false,
editable: true, 
edittype: 'select', 
editoptions: { 
    value: function() { return buildSelect(); } 
},
formatter: 'select'
}

but always shows the select?

I've got this working before with checkboxes, but there doesn't seem to be a way of doing it with selects. Ideally I'd like this to work in celledit mode. Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

All is possible. I am not sure, that what you want is the best way. In the most cases I recommend to use some standard way, then your live will be easier especially after change to a new version of the control which you use.

Nevertheless you can use custom formatter (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter) instead of formatter: 'select' to show the contain of a column how you as prefer. For example,

{ name: 'Options', width: 150, align: 'left', editable: true, edittype: 'select',
  editoptions: { 
    value: function() { return buildSelect(); } 
  },
  formatter: function (cellvalue, options, rowObject, action) {
    if (cellvalue === 'Yes') {
      return '<select><option value="1" selected="selected">Yes</option>' +
                     '<option value="0">No</option></select>';
    } else {
      return '<select><option value="1">Yes</option>' +
                    '<option value="0" selected="selected">No</option></select>';
    }
  }
}

can be used to display select with 'Yes' and 'No' values instead of default one current value ('Yes' or 'No'). You can also bind some function for a change handle of such select elements.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...