Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Periodical updates of Listgrid. Criteria Problems (startRow, endRow)

    Hi,
    i am using Smartclient 6.51 and use following code to refresh listgrids for displaying realtime data. The data does not disappear while fetching data in background. This works fine but I got some problems with the criteria.

    Listgrid:
    Code:
    isc.ListGrid.create( {
    	ID :"remarks_list_list1_0001",
    	componentTimestamp :"1231419451",
    	width :"100%",
    	height :"*",
    	minWidth :300,
    	membersMargin :10,
    	autoDraw :false,
    	autoFetchData :false,
    	alternateRecordStyles :true,
    	showAllRecords :false,
    	canGroupBy :false,
    	canSort :true,
    	showHeaderContextMenu :false,
    	wrapCells :true,
    	fixedRecordHeights :false,
    	loadingDataMessage :"Lade Daten...",
    	dataSource :"remarks_list_remarksds1_0001",
    	TI :null,
    	rowNum :-1,
    	timerInterval :60000,
    	timerEvent :null,
    	UI :"1_0001",
    	show : function() {
    		if (!remarksInfobox1_0001.isObserving(this, 'dataChanged')) {
    			remarksInfobox1_0001.observe(this, 'dataChanged','observer.updateInfo(this)');
    			this.startTimer(true);
    		} else {
    			if (null != this.timerEvent) {
    				isc.Timer.clear(this.timerEvent);
    			}
    			this.startTimer(false)
    		}
    		return this.Super('show', arguments);
    	},
    	startTimer : function(initial, force) {
    		var criteria = {};
    		if (remarks_list_list1_0001.data) {
    			if (remarks_list_list1_0001.data.criteria) {
    				criteria = remarks_list_list1_0001.data.criteria;
    			}
    		}
    		isc.addProperties(criteria, {
    			transId :isc.timeStamp(),
    			refresh :0,
    			metadata :sysReg.getRegistry('production').getRegistry(this.UI).getContext()
    		});
    		var interval = parseInt(this.timerInterval);
    		if (interval == 0) {
    		} else if (interval < 1000) {
    			interval = 5000;
    		}
    
    		if (initial == true) {
    			this.fetchData(criteria, function() {});
    			if (null != this.timerEvent) {
    				isc.Log.logInfo('TIMER CLEARED');
    				isc.Timer.clear(this.timerEvent);
    			}
    		} else {
    			if (!sysReg.getRegistry('client').getRecVal('modalState')) {
    				if ((remarks_list_list1_0001.isVisible() && remarks_list_list1_0001.isDrawn()) || (force == true)) {
    					this.selectedRowNum = this.data.indexOf(this.getSelectedRecord());
    					remarksInfobox1_0001.refreshing();
    					criteria.refresh = 1;
    					var compDs = this.dataSource;
    
    					if (null != this.timerEvent) {
    						isc.Log.logInfo('TIMER CLEARED');
    						isc.Timer.clear(this.timerEvent);
    					}
    					isc.DataSource.get(this.dataSource).fetchData(
    						criteria,
    						function(dsResponse, data, dsRequest, compDs) {
    							var res = remarks_list_list1_0001.data;
    							if (!res) {
    								var res = isc.ResultSet.create( {
    											dataSource :compDs,
    											allRows :data
    										});
    								remarks_list_list1_0001.setData(res);
    							}
    							res.allRows = data;
    							res.localData = data;
    							res.totalRows = dsResponse.totalRows;
    							res.dataChanged();
    							var rowNum = remarks_list_list1_0001.selectedRowNum;
    							if (rowNum >= 0) {
    								remarks_list_list1_0001.selectRecord(rowNum);
    							}
    							remarksInfobox1_0001.refreshSucess();
    							isc.Log.logInfo('TIMER RESTARTED');
    							var interval = parseInt(this.timerInterval);
    							if (interval > 0) {
    								this.timerEvent = Timer.setTimeout("remarks_list_list1_0001.startTimer(false)",interval);
    							}
    						}, 
    						{showPrompt :false,useSimpleHttp :true});
    				}
    			}
    		}
    		if (interval > 0) {
    			this.timerEvent = Timer.setTimeout("remarks_list_list1_0001.startTimer(false)",interval);
    		}
    	}
    });
    DataSource:

    Code:
    isc.DataSource.create( {
    	ID :"remarks_list_remarksds1_0001",
    	componentTimestamp :"1231419450",
    	dataFormat :"xml",
    	recordXPath :"/response/data/dataset/row",
    	dataTimestamp :null,
    	UI :"1_0001",
    	metadata : {
    		user :"oliver",
    		S :1,
    		D :520,
    		UI :"1_0001",
    		TI :"1_0001"
    	},
    	fields : [ {
    		name :'id',
    		type :'integer',
    		title :'Id',
    		primaryKey :true
    	}, {
    		name :'date',
    		title :'Datum'
    	}, {
    		name :'remark',
    		type :'text',
    		title :'Bemerkung'
    	} ],
    	transformRequest : function(dsRequest) {
    		this.Super('transformRequest', dsRequest);
    		dsRequest.timeout = 240000;
    		dsRequest.useSimpleHttp = true;
    		var params = {
    			metadata :sysReg.getRegistry('production').getRegistry('1_0001').getContext(),
    			startRow :dsRequest.startRow,
    			endRow :dsRequest.endRow,
    			sortBy :dsRequest.sortBy
    		};
    		return isc.addProperties( {}, dsRequest.data, params)
    	},
    	transformResponse : function(dsResponse, dsRequest, data) {
    		this.transformResponseCheck(dsResponse, dsRequest, data);
    		this.transformResponseValidation(dsResponse, dsRequest, data,'1_0001');
    		return dsResponse;
    	}
    });
    The Proble is that on initial fetch the criteria is set correct like this:
    http://myurl/remarks/list/fetch?transId=1231422389789&refresh=0&startRow=0&endRow=75&sortBy=null

    When the next time a refresh is triggered the parameter like startow, endRow and sortBy are undefined. But I need them to tell the server what SQL to perform.
    http://myurl/remarks/list/fetch?transId=1231422509867&refresh=1&startRow=null&endRow=null&sortBy=null

    I hope you could help me with this problem. I think it might have someting to do with the dsRequest in the transformRequest function.

    Thanks in advance!!!

    #2
    A direct call to DataSource.fetchData() knows nothing about the ListGrid or it's current sort direction. You need to pass any such properties via the requestProperties (third argument to DataSource.fetchData()).

    Comment

    Working...
    X