jqgrid - 保存前编辑时丢失的单元格数据

时间:2016-07-15 01:49:14

标签: jqgrid

无论保存之前编辑的最后一个字段是什么(如果我先不点击网格的任何其他部分),该字段中的数据将被HTML替换...例如,作为我输入的日期07/01 / 2016然后它保存为00/00/0000。当我在保存之前输出字段时,我看到以下html而不是日期:。除非在保存之前单击另一个单元格,否则不会保存单元格中的日期。请让我知道解决方案是什么?

代码:



	  jQuery("#billing_schedule").jqGrid({
		datatype: 'clientSide',
        //datatype: 'local',
		//editurl: 'clientArray',
		cellEdit: true,
		cellsubmit: 'clientArray',
        colNames:['','Date','Amount'],
        colModel :[ 
          {name:'btn', index:'btn', width:90, sortable:false}, 
		  {name:'date', index:'date', sortable:false, width:125, editable:true, editoptions:{size:"20"}},
		  {name:'amount', index:'amount', sortable:false, width:120, editable:true, editoptions:{size:"20"}}
		  ],
	    width: 350,
		height: 175,
		sortname:'date',
		sortorder: 'asc',
		viewrecords: true,
        imgpath: 'css/images',
		caption: '',
		altRows: false,
		beforeEditCell: function(rowid, cellname, value, iRow, iCol) {
			cellIsInEditMode = true;
			editedRow = iRow;
			editedCol = iCol;
		},
		afterSaveCell: function(rowid, cellname, value, iRow, iCol) {
			cellIsInEditMode = false;
			if (validateErrorPresent == true){
			   	  jQuery("#billing_schedule").setCell(rowid,"date",validatedVar,{},{});
			   validateErrorPresent = false;
			}
		},
		beforeSaveCell : function(rowid,celname,value,iRow,iCol) { 
		    //validate
			if( iCol==1 ) { //standardize the date
			   
			   if(d==null){
			     alert('Date string doesn\'t match any recognized formats!');
				 validateErrorPresent = true;
				 validatedVar = "invalid";
				 //jQuery("#billing_schedule").setRowData(ids[i],{date:""})
			   } else {
			     var newval = formatDate(d,'M/d/yyyy');
			     //jQuery("#billing_schedule").setRowData(rowid,{date:newval})
				 validatedVar = newval;
				 validateErrorColName = "date";
				 validateErrorPresent = true;
			   }
			}
	    },
		gridComplete: function() {

		}
	  
      }); 
	  getExistingSchedule();

<?php 
	  $urlToGet = $urlAppPath."php/person_status_includes.php?request=docready&isStudent=1&personID=".$studentID;
	  readfile($urlToGet);
?>	  
	   <?php
 if($scheduleID <> 0){ 
 ?>
     	    var currentTime = new Date();
        	var seconds = currentTime.getTime();
    		var s=htmlSendGrid();
        	httpObject = getHTTPObject();
            if (httpObject != null) {
               httpObject.open("GET", "php/predefined_schedules.php?action=get&scheduleID="+jQuery("#schedule_combo").val(), true);
               httpObject.send(null); 
               httpObject.onreadystatechange = loadExistingSchedule;
			}
 <?php
 }
 ?>
	
		$("a[rel]").overlay();

    }); 
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

当我添加了saveCellBeforeArray();  功能到我的保存功能

在我检索我的getHTTPObject以保存数据库之前,它工作了。我的保存功能基本上是:

    function onClickSave(){
      var ids = jQuery("#billing_schedule").getDataIDs();
      if (ids.length>0){        
        saveCellBeforeArray(); // fixed edit load problem
        var ids = jQuery("#billing_schedule").getDataIDs();
        var s;
        //load data from table
        for(var i=0;i<ids.length;i++){
            s = s+"&paymentDate="+jQuery("#billing_schedule").getCell(ids[i],1)+"&paymentAmount="+jQuery("#billing_schedule").getCell(ids[i],2);
        }
        httpObject = getHTTPObject();
...

&#13;
&#13;
	  jQuery("#billing_schedule").jqGrid({
		datatype: 'clientSide',
        //datatype: 'local',
		//editurl: 'clientArray',
		cellEdit: true,
		cellsubmit: 'clientArray',
        colNames:['','Date','Amount'],
        colModel :[ 
          {name:'btn', index:'btn', width:90, sortable:false}, 
		  {name:'date', index:'date', sortable:false, width:125, editable:true, editoptions:{size:"20"}},
		  {name:'amount', index:'amount', sortable:false, width:120, editable:true, editoptions:{size:"20"}}
		  ],
	    width: 350,
		height: 175,
		sortname:'date',
		sortorder: 'asc',
		viewrecords: true,
        imgpath: 'css/images',
		caption: '',
		altRows: false,
		beforeEditCell: function(rowid, cellname, value, iRow, iCol) {
			cellIsInEditMode = true;
			editedRow = iRow;
			editedCol = iCol;
		},
		afterSaveCell: function(rowid, cellname, value, iRow, iCol) {
			cellIsInEditMode = false;
			if (validateErrorPresent == true){
			   	  jQuery("#billing_schedule").setCell(rowid,"date",validatedVar,{},{});
			   validateErrorPresent = false;
			}
		},
		beforeSaveCell : function(rowid,celname,value,iRow,iCol) { 
		    //validate
			if( iCol==1 ) { //standardize the date
			   
			   if(d==null){
			     alert('Date string doesn\'t match any recognized formats!');
				 validateErrorPresent = true;
				 validatedVar = "invalid";
				 //jQuery("#billing_schedule").setRowData(ids[i],{date:""})
			   } else {
			     var newval = formatDate(d,'M/d/yyyy');
			     //jQuery("#billing_schedule").setRowData(rowid,{date:newval})
				 validatedVar = newval;
				 validateErrorColName = "date";
				 validateErrorPresent = true;
			   }
			}
	    },
		gridComplete: function() {

		}
	  
      }); 
	  getExistingSchedule();

<?php 
	  $urlToGet = $urlAppPath."php/person_status_includes.php?request=docready&isStudent=1&personID=".$studentID;
	  readfile($urlToGet);
?>	  
	   <?php
 if($scheduleID <> 0){ 
 ?>
     	    var currentTime = new Date();
        	var seconds = currentTime.getTime();
    		var s=htmlSendGrid();
        	httpObject = getHTTPObject();
            if (httpObject != null) {
               httpObject.open("GET", "php/predefined_schedules.php?action=get&scheduleID="+jQuery("#schedule_combo").val(), true);
               httpObject.send(null); 
               httpObject.onreadystatechange = loadExistingSchedule;
			}
 <?php
 }
 ?>
	
		$("a[rel]").overlay();

    }); 
&#13;
&#13;
&#13;

相关问题