Announcement

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

    ListGrid.setEditValues cannot change primaryKey field

    Hi,

    Why ListGrid.setEditValues cannot change value for field with primaryKey set to true, but setEditValue can?
    Any sugguestion.

    #2
    Please refer to my code ("No" field is primary key, calling setEditValues doesn't update new value to grid, but calling setEditValue individually it update new value to grid)
    Code:
            var orderData = [
                { No: 1, Item: "10010", Description: "Item 10010", Quantity: 10.0, Uom: "PCS", UnitPrice: 2.0 },
                { No: 2, Item: "10011", Description: "Item 10011", Quantity: 15.0, Uom: "PCS", UnitPrice: 2.5 },
                { No: 3, Item: "10012", Description: "Item 10012", Quantity: 20.0, Uom: "PCS", UnitPrice: 4.0 },
                { No: 4, Item: "10013", Description: "Item 10013", Quantity: 10.0, Uom: "PCS", UnitPrice: 3.0 },
                { No: 5, Item: "10014", Description: "Item 10014", Quantity: 15.0, Uom: "PCS", UnitPrice: 1.0 },
                { No: 6, Item: "10015", Description: "Item 10015", Quantity: 20.0, Uom: "PCS", UnitPrice: 1.5 }
            ];
                isc.DataSource.create({
                    ID: "orderDS",
                    fields: [
                    { name: "No", title: "No", type: "integer", primaryKey: true },
                    { name: "Item", title: "Item"},
                    { name: "Description", title: "Description" },
                    { name: "Quantity", title: "Quantity", type: "float" },
                    { name: "Uom", title: "Uom" },
                    { name: "UnitPrice", title: "Unit Price", type: "float" }
                ],
                    clientOnly: true,
                    testData: orderData
                });
                isc.ListGrid.create({
                    ID: "orderList",
                    width: 500, height: 224, alternateRecordStyles: true,
                    dataSource: orderDS,
                    autoFetchData: true,
                    autoSaveEdits: false,
                    canEdit: true, editEvent: "none",
                    recordDoubleClick: function (viewer, record, recordNum, field, fieldNum, value, rawValue) {
                        orderForm.editRecord(orderList.getEditedRecord(recordNum));
                        orderForm.setValue("No", orderForm.getValue("No") + 10);
                        orderForm.setValue("Item", orderForm.getValue("Item") + " ...");
                        orderForm.setValue("Description", orderForm.getValue("Description") + " ...");
                    }
                });
            isc.DynamicForm.create({
                ID: "orderForm",
                dataSource: orderDS,
                top: 250,
                width: 500,
                numCols: 4, colWidths: [50, 200, 50, 200]
            });
            isc.Button.create({
                title: "Change (setEditValues)", top: 230, width: 150, 
                click: function () {
                    if (orderForm.validate()) {
                        var rowNum = orderList.getRecordIndex(orderList.getSelectedRecord());
                        orderList.setEditValues(rowNum, orderForm.getValues());
                        orderForm.clearValues();
                    }
                }
            });
            isc.Button.create({
                title: "Change (setEditValue)", top: 230, width: 150, left: 200, 
                click: function () {
                    if (orderForm.validate()) {
                        var rowNum = orderList.getRecordIndex(orderList.getSelectedRecord());
                        orderList.setEditValue(rowNum, orderList.getColNum("No"), orderForm.getValue("No"));
                        orderList.setEditValue(rowNum, orderList.getColNum("Item"), orderForm.getValue("Item"));
                        orderList.setEditValue(rowNum, orderList.getColNum("Description"), orderForm.getValue("Description"));
                        orderList.setEditValue(rowNum, orderList.getColNum("Quantity"), orderForm.getValue("Quantity"));
                        orderList.setEditValue(rowNum, orderList.getColNum("Uom"), orderForm.getValue("Uom"));
                        orderList.setEditValue(rowNum, orderList.getColNum("UnitPrice"), orderForm.getValue("UnitPrice"));
                        orderForm.clearValues();
                    }
                }
            });
    Any idea???

    Comment


      #3
      Dear experts, am I doing the wrong way or there is a bug. Please advise.

      Comment


        #4
        Setting an edit value for the primary key field is not supported. It should be being disallowed in both cases.

        Update type operations (which occur when the grid's edit values are saved) make use of the primary key to identify which record on the server is being updated.
        In most use cases if you want a user to be able to edit a field value you would not want to make that your primary key. If you really need this, changing primary key could be supported by removing the record in question and adding a new one with the same properties and a new primary key value.

        Comment


          #5
          Noted with thanks.

          Comment


            #6
            Is there a recommended approach for this? Our legacy database has a number of tables where the primary key is user assigned and can be changed as long as there are no related records in other tables. It seems like the update criteria could just use the oldValue instead of the new value.

            Comment


              #7
              There are various ways you could solve this.

              One option would be an additional field not marked as primary key, which takes its data from the actual primary key field of the dataSource (via a chunk of custom SQL for example).
              This would be the field users would see and could edit. Then modify the update operation to handle this field being modified.
              On the server, use SQL templating or similar to ensure the correct field in the database table gets updated.
              On the client, you could use transformResponse / transformRequest to handle the fact that the primary key was actually changed. You could simply mark the request as "invalidateCache:true" to simply drop all associated cached data and refetch, or you could use "updateCaches()" to synthesize a remove and add type operation on the DataSource to explicitly yank out and re-add the record in question.

              Comment

              Working...
              X