Skip to content

Replies

0
Daniel Dority
Daniel Dority answered on Nov 9, 2015 7:45 PM

So the template is tricky.  We made the assumption that the template works like the igTemplating.  This is INCORRECT.  It only allows for one specific value which is ${id} (pay attention to the casing).  I have a primary key of Id so I suspected it followed the Primary Key syntax, which is also INCORRECT.  If your primary key is called "MyPrimaryKey" then you still specify ${id} in your rest setting template.  I guess this also means that the template doesn't support hierarchys or parent child relationships.  For example:

DELETE:  "/api/location/${locationId}/location/${id}"

Remove a carrier for a specific location.  Does the igGrid support this type of syntax?  The locationId would come from the row object that was selected.

Our problem is now solved, but I still wanted to make this point clear for others searching for an identical issue.

0
Daniel Dority
Daniel Dority answered on Nov 9, 2015 7:26 PM

I've played around with the settings and it still doesn't want to work.

I see why updates are working.  It is because our API is grabbing the ID off of the request body, not the URL.  The URL for the updates are also wrong.  They are being encoded when I expect the value of the ID to be seeded in the URL.

I expect:

  [POST]  /admin/api/carrier/1
  [DELETE] /admin/api/carrier/1

I tried toggling the value encodeRemoveInRequestUri but it did nothing.

The method you aren't familiar with is $.ced.createUri.  It formats URL's for us and appends the application root URL if needed.  In this case, I tried removing it from the equation and it still encoded the URL.

0
Daniel Dority
Daniel Dority answered on Nov 9, 2015 6:53 PM

Sorry I misunderstood what you meant by data binding. I modified the event and now it is correctly seeding the value. We have another event handler for deleting rows, here's the entire igGrid definition:

$.ced.ig.grid({
                id: "igGridCarriers",
                allowPaging: false,
                allowHiding: false,
                allowUndoRedo: false,
                emptyDataText: "THERE ARE NO CARRIERS AVAILABLE. CLICK TO ADD A CARRIER.",
                primaryKey: "Id",
                columns: [
                    { key: "Id", dataType: "number", hidden: true },
                    { key: "CarrierDescription", dataType: "string", headerText: "Description" },
                    { key: "StandardCarrierAlphaCode", dataType: "string", headerText: "AlphaCode" },
                    { key: "Display", dataType: "string", headerText: "Display", unbound: true, template: "${StandardCarrierAlphaCode} - ${CarrierDescription}" },
                    { key: "SortOrder", dataType: "number", hidden: true },
                    { key: "CreatedBy", dataType: "number", hidden: true },
                    { key: "CreatedDate", dataType: "date", hidden: true },
                    { key: "UpdatedBy", dataType: "number", hidden: true },
                    { key: "UpdatedDate", dataType: "date", hidden: true },
                    {
                         key: "Actions",
                         dataType: "string",
                         headerText: "",
                         width: "148px",
                         align: "center",
                         template: "×",
                         unbound: true
                    }
                ],
                features: [
                    {
                        name: "Filtering",
                        columnSettings: [
                            { columnKey: "Display", allowFiltering: false },
                            { columnKey: "Actions", allowFiltering: false },
                        ]
                    },
                    {
                        name: "Sorting",
                        columnSettings: [
                            { columnKey: "Display", allowSorting: false },
                            { columnKey: "Actions", allowSorting: false },
                        ]
                    },
                    {
                        name: "Updating",
                        editMode: "cell",
                        autoCommit: false,
                        enableAddRow: true,
                        enableDeleteRow: false,
                        columnSettings: [
                            { columnKey: "Display", readOnly: true },
                            { columnKey: "Actions", readOnly: true }
                        ],
                        rowAdding: function (e, ui) {
                            ui.values.CreatedDate = $.ig.formatter(ui.values.CreatedDate || new Date(), "date", "MM/dd/yyyy h:mm:ss tt", true, true, null);
                            ui.values.CreatedBy = ui.values.CreatedBy || 1;

                            ui.values.UpdatedDate = $.ig.formatter(new Date(), "date", "MM/dd/yyyy h:mm:ss tt", true, true, null);
                            ui.values.UpdatedBy = 1;
                        },
                        rowAdded: function (e, ui) {
                            var original = ui;

                            ui.owner.grid.saveChanges(function (record, status, response) {                                
                                ui.owner.updateRow(original.rowID, record);
                                original.owner.grid.dataBind();
                            });
                        },
                        editCellEnding: function (e, ui) {
                            if (ui.rowAdding) {
                                return;
                            }

                            if (ui.update === false) {
                                return false;
                            }

                            var row = ui.owner.grid.findRecordByKey(ui.rowID);

                            row.CreatedDate = $.ig.formatter(row.CreatedDate || new Date(), "date", "MM/dd/yyyy h:mm:ss tt", true, true, null);
                            row.CreatedBy = row.CreatedBy || 1;

                            row.UpdatedDate = $.ig.formatter(new Date(), "date", "MM/dd/yyyy h:mm:ss tt", true, true, null);
                            row.UpdatedBy = 1;

                            ui.owner.updateRow(ui.rowID, row);
                        },
                        editCellEnded: function (e, ui) {
                            if (ui.rowAdding) {
                                return;
                            }

                            ui.owner.grid.dataSource.saveChanges();
                        }
                    }
                ],
                restSettings: {
                    create: {
                        batch: false,
                        template: $.ced.createUri("/api/carrier"),
                        url: $.ced.createUri("/api/carrier")
                    },
                    update: {
                        batch: false,
                        template: $.ced.createUri("/api/carrier/${Id}"),
                        url: $.ced.createUri("/api/carrier")
                    },
                    remove: {
                        batch: false,
                        template: $.ced.createUri("/api/carrier/${Id}"),
                        url: $.ced.createUri("/api/carrier")
                    }
                },
                dataSource: $.ced.createUri("/api/carrier")
            });

Our remove template is setup for deleting items but this is what we see: DELETE /admin/api/carrier/$%7BId%7D HTTP/1.1 The template is escaping the values instead of seeding it with the ID. Updates work great! What gives?