views:

562

answers:

2

I'm creating a jqgrid with one drop down column. I need the options of the drop down columns to change dynamically so I thought I can catch the beforeCellEdit event.

however it does not seem to be firing. any idea on what i am doing wrong? there is no error, and i did check that i have included the jqgrid edit js files.

var lastsel2;
jQuery(document).ready(function(){ 
    jQuery("#projectList").jqGrid({
        datatype: 'json',
        url:'projectDrv.jsp',
        mtype: 'GET',
        height: 250,
        colNames:['Node','Proposal #', 'Status', 'Vendor', 'Actions'],
        colModel :[ 
          {name:'node', index:'node', width:100, editable:false, sortable:false},
          {name:'proposal', index:'proposal', width:100, editable:false, resizable:true }, 
          {name:'status', index:'status', width:100, resizable:true, sortable:false, editable:false  },
          {name:'vendor', index:'vendor', width:100, resizable:true, editable:false, sortable: false },
          {name:'actions', index:'actions', width:100, resizable:true, sortable:false, editable: true, edittype:"select" }
        ],
        pager: '#pager',
        rowNum: 10,
        sortname: 'proposal',
        sortorder: 'desc',
        viewrecords: true,
        onSelectRow: function(id){ 
          if (id && id!==lastsel2){ 
            jQuery('#projectList').jqGrid('restoreRow',lastsel2); 
            jQuery('#projectList').jqGrid('editRow',id,true); 
            lastsel2 = id; 
          } 
        }, 
        beforeEditCell: function(rowid, cellname, value, irow, icol) { 
          alert("before edit here " + rowid);
          // set editoptions here
        }

});

A: 

Instead of using beforeEditCell you might consider specifying a formatter function in your call to editRow:

jQuery('#projectList').jqGrid('editRow',id,true,formatEditors); 

Then, this function can be used to setup your dropdown:

function formatEditors(id) {
    // Initialize dropdown for the row, using jQuery selector:
    // jQuery("#" + id + "_actions", "#projectList")
}
Justin Ethier
in formatEditors i have this code: alert("test");jQuery("#projectList").setColProp( 'actions', { edittype: "select", editoptions:{value:"True:False"} } );and it does not get called if my original colmodel has the "actions" coloumn with edittype:"select". if i don't set the edittype, this function get called but drop down an empty list.(the drop down contents will eventually be dynamic).
mango
A: 

I believe the reason beforeEditCell isn't firing is that you don't have "cellEdit: true" in your parent grid.

ie:

    ...
    viewrecords: true,
    cellEdit: true,
    onSelectRow: function(id){ 
      if (id && id!==lastsel2){ 
        jQuery('#projectList').jqGrid('restoreRow',lastsel2); 
        jQuery('#projectList').jqGrid('editRow',id,true); 
        lastsel2 = id; 
      } 
    }, 
    beforeEditCell: function(rowid, cellname, value, irow, icol) { 
      alert("before edit here " + rowid);
      // set editoptions here
    }

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:cell_editing#properties

Red Sparrow