2017-06-21 76 views
1

對於數據網格在quiting編輯模式,我用DevExtreme DataGrid和內容文本放在文本區域,如:防止從DevExtreme JS的DataGrid

$("#test").dxDataGrid({ 
    columns: [ 
    { 
     ... 
     customizeText: function(cellInfo) { 
     return cellInfo.value.replace(/(?:\r\n|\r|\n)/g, "<br/>"); 
     }, 
     editCellTemplate: function(cellElement, cellInfo) { 
        var $input; 
        var numberOfCariage = cellInfo.value.split('\n').length; 

        // if is textarea (by seeing if contains cariage return 
        if (/(?:\r\n|\r|\n)/g.test(cellInfo.value)) { 
        $input = $('<textarea rows="' + numberOfCariage + '" class="dx-texteditor-input" />'); 
        } else { 
        $input = $('<input autocomplete="off" class="dx-texteditor-input" spellcheck="false" tabindex="0" name="" role="textbox" style="text-align: left;" type="text" />'); 
        } 

        $input.val(cellInfo.value); 
        $(cellElement).append($input); 
        cellInfo.setValue(function() { 
        return $input.val(); 
        }); 
     } 
    } 
    ], 

    editing: { 
     mode: "row", 
     allowUpdating: true 
    } 
}); 

的問題是,如果我編輯單元格是文本區域,如果我按ENTER在該textarea中添加新行,我退出編輯模式。

如何預防?

回答

0

stopPropagation方法將有助於你的情況。

只需添加​​事件處理程序爲您的textarea:

$input.on('keydown', function(e) { 
    // Check if pressed key is 'Enter' 
    if(e.keyCode === 13) { 
     e.stopPropagation(); 
    } 
}); 

看到的結果在行動嘗試編輯在此demo「位置」。

+1

是的,我也想到這個解決方案:) –