Announcement

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

    Warning when using updataData on clientOnly DataSource

    SmartClient: v9.0p_2013-08-19 (2013-08-19)

    I am trying to update the data in a ListGrid that uses a clientOnly DataSource, but when I call the ListGrid.updateData(updatedRecord), a warning message is being shown: "clientOnly update operation failed: unable to find matching record. Did you supply all primaryKeys?".

    As I could see, I'm supplying all the primaryKeys. Is there any additional step I need to do for that to work?

    The code below tries to update a record from the ListGrid after 3 seconds.

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <title>Test Update client only DataSource</title>
    <script>var isomorphicDir = "isomorphic/";</script>
    <script src="isomorphic/system/modules/ISC_Core.js"></script>
    <script src="isomorphic/system/modules/ISC_Foundation.js"></script>
    <script src="isomorphic/system/modules/ISC_Containers.js"></script>
    <script src="isomorphic/system/modules/ISC_Grids.js"></script>
    <script src="isomorphic/system/modules/ISC_Forms.js"></script>
    <script src="isomorphic/system/modules/ISC_DataBinding.js"></script>
    <script src="isomorphic/skins/Enterprise/load_skin.js"></script>
    <script>
    
        (function(root) {
    
            var test = root.test = {};
    
            test.createListGrid = function() {
                isc.ListGrid.create({
                    ID: "listGrid",
                    width: 500,
                    height: 300,
                    dataSource: test.createDataSource()
                });
            };
    
            test.fields = [
                {
                    name : "id",
                    title : "ID",
                    type : "integer",
                    hidden: true,
                    primaryKey: true
                }, {
                    name : "itemName",
                    title : "Item",
                    type : "text"
                }, {
                    name : "unitCost",
                    title : "Unit Cost",
                    type : "integer"
                }
            ];
    
            test.createDataSource = function() {
                var dataSource = test.dataSource = isc.DataSource.create({
                    ID: "listGridDataSource",
                    clientOnly: true,
                    fields: test.fields        
                });
                
                return dataSource;
            };
           
            test.init = function() {
                
                test.count = 30;
                test.unitCost = 0;
    
                test.createListGrid();
                
                listGrid.setData(test.generateData(test.count, test.unitCost));
                
                setTimeout(test.updateData, 3000);
            };
            
            test.generateData = function(count, unitCost) {
                
                var data = [];
                var item;
                
                for (var i = 0; i < count; i++) {
                    item = {
                        itemName: "itemName" + (i < 10 ? "0" : "") + i,
                        unitCost: unitCost,
                        id: 100 + i
                    };
                    data[data.length] = item;
                }
                
                return data;
            };
            
            test.updateData = function() {
                
                var updatedRecord = isc.addProperties(
                    listGrid.getRecord(0),
                    {unitCost: 100}
                );    
                
                listGrid.updateData(updatedRecord);
            };
    
        })(this);
    
    
        </script>
    </head>
    <body onload="test.init();">
    </body>
    </html>
    Last edited by ueng; 16 Sep 2013, 06:34. Reason: Removing environment specific path

    #2
    You are mixing dataSource and non-DS oriented listGrid methods. setData is used when not using a datasource. In your case call listGrid.addData() on each generated record to push it into the datasource. Then add autoFetchData:true to the listGrid definition so it will load data as it becomes available.

    Finally, I recommend the following change to how you update your record:
    Code:
                var existingRecord = listGrid.getRecord(0),
                    updatedRecord = { 
                        id: existingRecord.id,
                        unitCost: 100
                    }
                ;
    This avoids updating the record directly and does so only through data-binding operations.

    Comment

    Working...
    X