Go Back   SmartClient Forums > Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13th Mar 2008, 16:04
picasso566 picasso566 is offline
Registered Developer
 
Join Date: Sep 2007
Posts: 181
Default Grid refreshes when a record is saved

I have a ListGrid and a DynamicForm both tied to the same Datasource:

Code:
isc.DataSource.create({
        ID:"registrationsDS",
        showPrompt: false,
        dataFormat: "xml",
        dataURL:"/browse/isotest/Registrations.ashx",
        recordXPath : "//user",
        fields:[
            { name : "userid", title:"UserId"},
            { name : "registrationDate", title:"Reg Date", width: 120},
            { name : "namefirst", title:"First", width: 150 },
            { name : "namemiddle", title:"Middle", width: 75},
            { name : "namelast", title:"Last", width: 150},
            { name : "email", title:"Email", width: 220},
            { name : "company", title:"Company", hidden: companyHidden},
            { name : "letters", title:"Letters", hidden: lettersHidden},
            { name : "salesrepid", title:"Sales Rep Id", hidden: true},    
            { name : "salesrep", title:"Sales Rep", hidden: salesRepHidden},
            { name : "comments", title:"Comment", hidden: true}
            
        ],
        transformRequest : function (dsRequest) {return RequestFields(dsRequest, "registrations");},
        transformResponse: function (dsResponse,dsRequest,xmlData) {return ResponseFields(dsResponse,dsRequest,xmlData, "users");}
    });


 isc.DynamicForm.create({
	    ID:"RegistrationEditForm",
	    useAllDataSourceFields:true,
	    dataSource: "registrationsDS",
	    fields:[
	            { name : "email",  title:"Email", width : 200},
	            { name : "phone", title:"Phone", width : 200},
                { name : "namefirst",  title:"First", width : 200 },
                { name : "company",  title:"Company", width : 200},
                { name : "namelast",  title:"Last", width : 200},
                { type : "textarea", name : "letters", title:"Letters", height: 50, width : 200, rowSpan: 2},
                { name : "addressone",  title:"Address 1", width : 200},
                { name : "addresstwo",  title:"Address 2", width : 200},
                { type : "textarea", name : "comments", title:"Comments", width : 200, rowSpan: 4},
                { name : "city",  title:"City", width : 200},
                { name : "state",  title:"state", width : 200},
                { name : "zip",  title:"Zip", width : 200},
                {name:"savebtn", editorType:"button", align:"center", 
                    width:75, title:"Save", click:"RegistrationEditForm.saveData()", startRow:true, endRow:false},
                {name:"activatebtn", editorType:"button", align:"center", 
                    width:75, title:"Activate", click:"ActivateFromEditor()", startRow:false, endRow:false},
                {name:"deleteRegbtn", editorType:"button", align:"center", 
                    width:75, title:"Delete", click:"", startRow:false, endRow:false},
                {name:"regAssignGroupsbtn", editorType:"button", align:"center", 
                    width:150, title:"Assign Usergroups", click:"", startRow:false, endRow:false}
            ],
	    width:"100%",
	    numCols:4,
	    colWidths:[75,75,75,75],
        margin:5,
        overflow: "auto",
	    cellPadding:5,
	    autoFocus:false,
	    clearDetails : function () {
	        regId = 0;
	        RegistrationEditForm.editNewRecord();
	        UsergroupsForRegList.data.invalidateCache();
            UsergroupsForRegList.fetchData({ ts : isc.timeStamp() });
	    }
    });


isc.ListGrid.create({
        ID: "registrationList", 
        alternateRecordStyles:true,
        showAllRecords:false,
        dataSource: "registrationsDS",
        dataPageSize: 10,
        autoFetchData: true,
        drawAheadRatio: 1,
        showFilterEditor: false,
        cellContextClick:"return registrationListMenu.showContextMenu()",
        recordClick:"this.updateDetails()",
	    canEdit:true,
        modalEditing:true,
	    cellChanged:"this.updateDetails()",
	    updateDetails : function () {
            var record = this.getSelectedRecord();
            if (record == null) return RegistrationEditForm.clearDetails();
            if(registrationList.getSelection().getLength() == 1){
                RegistrationEditForm.editRecord(record);
                regId = record.userid;
                
                UsergroupsForRegList.data.invalidateCache();
                UsergroupsForRegList.fetchData({ ts : isc.timeStamp() });
                
                RegistrationEditForm.disabled = false;
                }
            else {
                regId = 0;
                UsergroupsForRegList.data.invalidateCache();
                UsergroupsForRegList.fetchData({ ts : isc.timeStamp() });
                
                RegistrationEditForm.clearDetails();
                RegistrationEditForm.disabled = true;
            }  
        }
    });


function ResponseFields(dsResponse,dsRequest,xmlData, rootName){
        if (dsRequest.operationType == "fetch") {
                if( xmlData ) {
                    dsResponse.totalRows = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@totalrecords");
                    dsResponse.startRow = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@startRow");
                    dsResponse.endRow = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@endRow");
                    dsResponse.sortBy = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@sortBy");
                    }
                }
            return dsResponse;
    }
    
    function RequestFields(dsRequest, methodObj, addParms){
            if (dsRequest.operationType == "update") {
                var params = {
                    startRow : dsRequest.startRow,
                    endRow : dsRequest.endRow,
                    method : "update_" + methodObj,
                    sortBy: (dsRequest.sortBy == 'undefined') ? "" : dsRequest.sortBy,
                    global: filterFieldVal
                };
                return isc.addProperties({}, dsRequest.data, params);
            }
    
    
            if (dsRequest.operationType == "fetch") {
                var params = {
                    startRow : dsRequest.startRow,
                    endRow : dsRequest.endRow,
                    method : "fetch_" + methodObj,
                    sortBy: (dsRequest.sortBy == 'undefined') ? "" : dsRequest.sortBy,
                    global: filterFieldVal
                };
                return isc.addProperties({}, dsRequest.data, params);
            }
    }
When the Form is saved (saveData() is called) , the grid refreshes instead of just updating the single record. What circumstanses would cause this to occur? The update call returns a single registration record in XML format.


Thanks in advance,

Paul
Reply With Quote
  #2  
Old 13th Mar 2008, 16:34
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,393
Default

You don't seem to have a primaryKey field declared (which is how SmartClient identifies records when talking to the server).

You might also need this patch although it's unlikely.

The best way to troubleshoot this is to enable the ResultSet log category (set to DEBUG) in order to watch what's happening as SmartClient tries to update your cache with the new record values.
Reply With Quote
  #3  
Old 14th Mar 2008, 08:22
picasso566 picasso566 is offline
Registered Developer
 
Join Date: Sep 2007
Posts: 181
Default Add the primaryKey still refreshes

I was so sure I had a primaryKey field, I didn't even review it in my code, even when posting it.

I have added the primaryKey field property to the datasource as wll as the type property to all the fields. Below is my new Datasource definition. It is still refreshing. I noticed in the sample application, that in the dsResponse for RPC calls we have the following properties:

invalidateCache = false
status = 0
isDSResponse = true

Because I am using an xml datasource (.net on the backend) I am doing a transform request/response as you can see in my code. Do I need to set the above properties for the response object? My transformResponse code is included below.

Thanks

Paul

Code:

    var filterFieldVal = "";
    
    function ResponseFields(dsResponse,dsRequest,xmlData, rootName){
        if (dsRequest.operationType == "fetch") {
                if( xmlData ) {
                    dsResponse.totalRows = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@totalrecords");
                    dsResponse.startRow = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@startRow");
                    dsResponse.endRow = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@endRow");
                    dsResponse.sortBy = isc.XMLTools.selectNumber(xmlData, "//" + rootName + "/@sortBy");
                    }
                }
        if(dsRequest.operationType == "update"){
             dsResponse.invalidateCache = false;
             dsResponse.status = 0;
             dsResponse.isDSResponse = true;
        }                
            return dsResponse;
    }
    
    function RequestFields(dsRequest, methodObj, addParms){
            if (dsRequest.operationType == "update") {
                var params = {
                    //startRow : dsRequest.startRow,
                    //endRow : dsRequest.endRow,
                    method : "update_" + methodObj
                    //,
                    //sortBy: (dsRequest.sortBy == 'undefined') ? "" : dsRequest.sortBy,
                    //global: filterFieldVal
                };
                return isc.addProperties({}, dsRequest.data, params);
            }
    
    
            if (dsRequest.operationType == "fetch") {
                var params = {
                    startRow : dsRequest.startRow,
                    endRow : dsRequest.endRow,
                    method : "fetch_" + methodObj,
                    sortBy: (dsRequest.sortBy == 'undefined') ? "" : dsRequest.sortBy,
                    global: filterFieldVal
                };
                
                return isc.addProperties({}, dsRequest.data, params);
            }
    }
    
    
    var companyHidden = false; //((divid == 1)? true : false );
    var lettersHidden = ((divid == 1)? false : true );
    var salesRepHidden = ((divid == 1)? true : false );
    
    //alert(companyHidden + '\n' + lettersHidden + '\n' + salesRepHidden );
    
    isc.DataSource.create({
        ID:"registrationsDS",
        showPrompt: false,
        dataFormat: "xml",
        dataURL:"/browse/isotest/Registrations.ashx",
        recordXPath : "//user",
        fields:[
            { name : "userid", title:"UserId", primaryKey: true, type: "sequence"},
            { name : "registrationDate", title:"Reg Date", width: 120, type: "text"},
            { name : "namefirst", title:"First", width: 150 , type: "text"},
            { name : "namemiddle", title:"Middle", width: 75, type: "text"},
            { name : "namelast", title:"Last", width: 150, type: "text"},
            { name : "email", title:"Email", width: 220, type: "text"},
            { name : "company", title:"Company", hidden: companyHidden, type: "text"},
            { name : "letters", title:"Letters", hidden: lettersHidden, type: "text"},
            { name : "salesrepid", title:"Sales Rep Id", hidden: true, type: "text"},    
            { name : "salesrep", title:"Sales Rep", hidden: salesRepHidden, type: "text"},
            { name : "comments", title:"Comment", hidden: true, type: "text"}
            
        ],
        transformRequest : function (dsRequest) {return RequestFields(dsRequest, "registrations");},
        transformResponse: function (dsResponse,dsRequest,xmlData) {return ResponseFields(dsResponse,dsRequest,xmlData, "users");}
    });
Reply With Quote
  #4  
Old 14th Mar 2008, 11:15
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,393
Default

No, you don't need those properties.

Have you tried the patch?

What are you seeing when the ResultSet log is enabled?
Reply With Quote
  #5  
Old 14th Mar 2008, 11:49
picasso566 picasso566 is offline
Registered Developer
 
Join Date: Sep 2007
Posts: 181
Default

Yes, I applied the patch and here is the result from the ResultSet log:

Code:
12:47:19.527:DEBUG:ResultSet:isc_ResultSet_18:getRange: guessing forward scrolling
12:47:19.527:INFO:ResultSet:isc_ResultSet_18:getRange(0, 9) will fetch from 0 to 10
12:47:19.527:INFO:ResultSet:isc_ResultSet_18:fetching rows 0,10 from server
12:47:19.558:DEBUG:DynamicForm:RegistrationEditForm:blur w/o handler: no item to blur
12:47:19.574:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_0 name:userid]
12:47:19.589:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_1 name:registrationDate]
12:47:19.605:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_2 name:namefirst]
12:47:19.605:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_3 name:namemiddle]
12:47:19.621:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_4 name:namelast]
12:47:19.636:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_5 name:email]
12:47:19.636:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_6 name:phone]
12:47:19.652:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_7 name:company]
12:47:19.668:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextAreaItem ID:isc_TextAreaItem_8 name:letters]
12:47:19.683:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_9 name:addressone]
12:47:19.699:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_10 name:addresstwo]
12:47:19.714:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_11 name:city]
12:47:19.730:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_12 name:state]
12:47:19.730:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [TextItem ID:isc_TextItem_13 name:zip]
12:47:19.746:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [ButtonItem ID:isc_ButtonItem_14 name:savebtn]
12:47:19.761:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [ButtonItem ID:isc_ButtonItem_15 name:activatebtn]
12:47:19.777:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [ButtonItem ID:isc_ButtonItem_16 name:deleteRegbtn]
12:47:19.808:DEBUG:DynamicForm:RegistrationEditForm:Drawing FormItem: [ButtonItem ID:isc_ButtonItem_17 name:regAssignGroupsbtn]
12:47:19.964:DEBUG:ResultSet:isc_ResultSet_18:getRange(0, 9) satisfied from cache
12:47:20.089:WARN:Log:operationBinding is: DataSource{ID: "UserGroupsForRegDS",
showPrompt: false,
dataFormat: "xml",
dataURL: "/browse/isotest/Usergroups.ashx",
recordXPath: "//usergroup",
fields: Obj,
canQueueRequests: false,
name: "UserGroupsForRegDS",
mergedFields: Obj,
xmlNamespaces: Obj}
12:47:20.105:INFO:ResultSet:isc_ResultSet_18:Received 0 records from server
12:47:20.136:WARN:ResultSet:isc_ResultSet_18:fetchData callback: dsResponse.endRow set to:10. dsResponse.totalRows set to:0. endRow cannot exceed total dataset size. Clamping endRow to the end of the dataset (0).
12:47:20.152:DEBUG:ResultSet:isc_ResultSet_18:full length set to: 0
12:47:20.168:DEBUG:ResultSet:isc_ResultSet_18:integrating 0 rows into cache at position 0
12:47:20.199:INFO:ResultSet:isc_ResultSet_18:cached 0 rows, from 0 to 0 (0 total rows, 0 cached)
12:47:20.214:INFO:ResultSet:isc_ResultSet_18:Cache for current criteria complete
12:47:20.261:DEBUG:ResultSet:isc_ResultSet_18:getRange(0, 0): returning empty list
12:47:26.199:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'userid' with value '5281'
12:47:26.215:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'registrationDate' with value '06/01/2007'
12:47:26.246:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'namefirst' with value 'Cris B'
12:47:26.261:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'namemiddle' with value 'undefined'
12:47:26.293:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'namelast' with value 'Aglar'
12:47:26.308:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'email' with value 'cr****uilar@******nnel.com'
12:47:26.340:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'company' with value 'Clear Channel Communications'
12:47:26.355:DEBUG:DynamicForm:RegistrationEditForm:Applying 1 validators to field 'letters' with value 'WHP'
12:47:26.590:WARN:Log:operationBinding is: DataSource{ID: "registrationsDS",
showPrompt: false,
dataFormat: "xml",
dataURL: "/browse/isotest/Registrations.ashx",
recordXPath: "//user",
fields: Obj,
canQueueRequests: false,
name: "registrationsDS",
mergedFields: Obj,
xmlNamespaces: Obj}
12:47:26.621:DEBUG:ResultSet:isc_ResultSet_22:dataSource data changed firing
12:47:26.636:INFO:ResultSet:isc_ResultSet_22:Invalidating cache
12:47:26.761:DEBUG:ResultSet:isc_ResultSet_22:getRange(0,15), cache check: 2,12 firstMissingRow: 2 lastMissingRow: 12
12:47:26.793:DEBUG:ResultSet:isc_ResultSet_22:getRange: no scrolling direction detected
12:47:26.824:INFO:ResultSet:isc_ResultSet_22:getRange(0, 15) will fetch from 0 to 15
12:47:27.090:DEBUG:ResultSet:isc_ResultSet_22:getRange(0,15), cache check: 2,12 firstMissingRow: 2 lastMissingRow: 12
12:47:27.121:DEBUG:ResultSet:isc_ResultSet_22:getRange: no scrolling direction detected
12:47:27.152:INFO:ResultSet:isc_ResultSet_22:getRange(0, 15) will fetch from 0 to 15
12:47:27.527:INFO:ResultSet:isc_ResultSet_22:fetching rows 0,15 from server
12:47:27.652:WARN:Log:operationBinding is: DataSource{ID: "registrationsDS",
showPrompt: false,
dataFormat: "xml",
dataURL: "/browse/isotest/Registrations.ashx",
recordXPath: "//user",
fields: Obj,
canQueueRequests: false,
name: "registrationsDS",
mergedFields: Obj,
xmlNamespaces: Obj}
12:47:27.730:INFO:ResultSet:isc_ResultSet_22:Received 16 records from server
12:47:27.761:DEBUG:ResultSet:isc_ResultSet_22:full length set to: 128
12:47:27.793:DEBUG:ResultSet:isc_ResultSet_22:integrating 16 rows into cache at position 0
12:47:27.824:INFO:ResultSet:isc_ResultSet_22:cached 16 rows, from 0 to 15 (128 total rows, 16 cached)
12:47:27.871:DEBUG:ResultSet:isc_ResultSet_22:getRange(0, 15) satisfied from cache
Reply With Quote
  #6  
Old 14th Mar 2008, 12:07
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,393
Default

Hi Picasso,

What version of SmartClient is this? Prior to 6.0 the behavior for a completed "update" operation when the dataset is paged was to invalidate the cache since the row order could get out of sync between client and server, so a refetch of the dataset would be expected and is shown in the logs.

This invalidation behavior changed in 6.0 with the updatePartialCache feature.
Reply With Quote
  #7  
Old 14th Mar 2008, 12:09
picasso566 picasso566 is offline
Registered Developer
 
Join Date: Sep 2007
Posts: 181
Default

I'm using smartclient v6 small vendor's edition
Reply With Quote
  #8  
Old 14th Mar 2008, 12:11
picasso566 picasso566 is offline
Registered Developer
 
Join Date: Sep 2007
Posts: 181
Default

How can I make sure, I am using a particular version of Smartclient?
Reply With Quote
  #9  
Old 14th Mar 2008, 12:16
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,393
Default

The version is reported in the lower left hand corner of the Developer Console.
Reply With Quote
  #10  
Old 14th Mar 2008, 12:43
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 38,393
Default

Assuming you're really on 6.0, the mystery is these logs:

Code:
12:47:26.621:DEBUG:ResultSet:isc_ResultSet_22:dataSource data changed firing
12:47:26.636:INFO:ResultSet:isc_ResultSet_22:Invalidating cache
There is no apparent way in 6.0 to go from the first log to the second log without an intervening log that explains the rationale for the cache being dropped.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


© 2010,2011 Isomorphic Software. All Rights Reserved