easyui中編輯單個單元格

//這裏用在datagrid中,編輯單個單元格並實時保存。如果在datagrid中有不同的字段,控件不同,還可以將字段的field值與設定字段比較來控制改字段是否可編輯。
 var currentfield = undefined;
  var currentIndex = undefined;
 function onClickCell(rowIndex, field, value) {
         if (field != undefined) {
            if (currentIndex != undefined)
            {   var ed = $('#grid').datagrid('getEditor', {index:currentIndex,field:currentfield});
                var value=$(ed.target).datebox('getValue');
                if(value&&value.length>0)
                { if (!value.match(/^((((19|20)\d{2})-(0?(1|[3-9])|1[012])-(0?[1-9]|[12]\d|30))|(((19|20)\d{2})-(0?[13578]|1[02])-

31)|(((19|20)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))-0?2-29))$/)) {
                    $.messager.alert("提示", "時間格式有誤,數據回滾!");
                    $('#grid').datagrid('rejectChanges');
                    coll = $('#grid').datagrid('getColumnOption', currentfield);
                    coll.editor = null;
                    currentIndex = undefined;
                    currentfield = undefined;
                    return;
                }
                }
                $("#grid").datagrid('endEdit', currentIndex);
                if (currentfield != undefined) {
                    coll = $('#grid').datagrid('getColumnOption', currentfield);
                    coll.editor = null;
                }
                var changes=$("#grid").datagrid("getChanges");
                $('#grid').datagrid('acceptChanges');
                var changedatas=JSON.stringify(changes);
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {datas:changedatas},
                    url: '/FundPurchasingManagement/PurchasingExecEntering/UpdatePurchaseTaskPlan',
                    async: false,
                    error: function (request) {
                        alert("Connection?error");
                    },
                    success: function (data) {
                        if(!data.success)
                            $.messager.alert('溫馨提示', data.msg, 'info');
                      

                    }
                })
            }
            col = $('#grid').datagrid('getColumnOption', field);
            col.editor = { type: 'datebox', options: { align: 'center'} };
            $("#grid").datagrid('beginEdit', rowIndex);
            currentIndex = rowIndex;
            currentfield = field;
        }
        else {

            currentIndex = undefined;
            currentfield = undefined;
        }
       
    }



實現的效果爲:

這是在datagrid中使用了datebox


發佈了31 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章