How to get a jqGrid cell value when editing

前端 未结 23 2265
日久生厌
日久生厌 2020-11-27 17:43

How to get a jqGrid cell value when in-line editing (getcell and getRowData returns the cell content and not the actuall value of the input element).

相关标签:
23条回答
  • 2020-11-27 18:37

    As you stated, according to the jqGrid documentation for getCell and getRowData:

    Do not use this method when you editing the row or cell. This will return the cell content and not the actual value of the input element

    Since neither of these methods will return your data directly, you would have to use them to return the cell content itself and then parse it, perhaps using jQuery. It would be nice if a future version of jqGrid could provide a means to do some of this parsing itself, and/or provide an API to make it more straightforward. But on the other hand is this really a use case that comes up that often?

    Alternatively, if you can explain your original problem in more detail there may be other options.

    0 讨论(0)
  • 2020-11-27 18:38

    General function to get value of cell with given row id and cell id

    Create in your js code function:

    function getCellValue(rowId, cellId) {
        var cell = jQuery('#' + rowId + '_' + cellId);        
        var val = cell.val();
        return val;
    }
    

    Example of use:

    var clientId = getCellValue(15, 'clientId');
    

    Dodgy, but works.

    0 讨论(0)
  • 2020-11-27 18:38

    I think a better solution than using getCell which as you know returns some html when in edit mode is to use jquery to access the fields directly. The problem with trying to parse like you are doing is that it will only work for input fields (not things like select), and it won't work if you have done some customizations to the input fields. The following will work with inputs and select elements and is only one line of code.

    ondblClickRow: function(rowid) {
        var val = $('#' + rowid + '_MyCol').val();
    }
    
    0 讨论(0)
  • 2020-11-27 18:40

    I obtain edit value using javascript:

    document.getElementById('idCell').value

    I hope this info useful for someone.

    0 讨论(0)
  • 2020-11-27 18:42

    You can use getCol to get the column values as an array then index into it by the row you are interested in.

    var col = $('#grid').jqGrid('getCol', 'Sales', false);
    
    var val = col[row];
    
    0 讨论(0)
提交回复
热议问题