Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - SMV93

Pages: [1]
1
This issue is grid.commit not firing when the colModel allows nullable numbers. Sending editable: false columns back to the server is not the issue.

When adding a blank row, nullable number values have to be added to rowData as null or grid.commit will not fire. Example code below.

Code: [Select]
var rowIndx = $grid.pqGrid("addRow", { rowData: {
   //Handle nullable number values
   Purchase_Price: null,
   Rate_Per_Hour: null,
   Sell_Price: null,
   Year_Model: null
}

In addition, editable: false, dataType: "float" columns had to be changed to dataType: "string" to fire grid.commit.

Code: [Select]
                    {
                        title: "Depreciation Years", dataType: "string", dataIndx: "Depreciation_Years", width: 100, editable: false,
                        render: function (ui) {
                            var cellData = ui.cellData;
                            var rowData = ui.rowData[2];
                            console.log(rowData);
                            if (cellData != null && cellData != "") {
                                return parseFloat(ui.cellData).toFixed(2);
                            }
                        }
                    },

                    {
                        title: "NBV", dataType: "string", dataIndx: "Net_Book_Value", width: 100, align: 'right', editable: false,
                        render: function (ui) {
                            var cellData = ui.cellData;
                            if (cellData != null && cellData != "") {
                                return "$" + parseFloat(ui.cellData).toFixed(2);
                            }
                        }
                    },


After these changes grid.commit fires when addList is returned. This allows the recIndx to be updated and eliminates primary key issues.

2
I found the issue is related to grid.commit not being triggered when the row is returned from the server. This causes the recIndx to not be updated. Are there certain conditions that would cause commit to not be triggered? Possibly related to the colModel? I have another pqGrid with the same change code and it works flawlessly. The only major difference between the two grids is the colModel.

This is my change code related to commit:

Code: [Select]

                change: function (evt, ui) {
                    console.log(ui.source);
                    if (ui.source == 'commit' || ui.source == 'rollback') {
                        return;
                    }
                    console.log(ui);
                    var $grid = $(this),
                        grid = $grid.pqGrid('getInstance').grid;
                    var rowList = ui.rowList,
                        recIndx = grid.option('dataModel').recIndx,
                        addList = [],
                        updateList = [],
                        deleteList = [];

                    for (var i = 0; i < rowList.length; i++) {
                        var obj = rowList[i],
                            rowIndx = obj.rowIndx,
                            newRow = obj.newRow,
                            type = obj.type,
                            rowData = obj.rowData;
                        if (type == 'add') {
                            var valid = grid.isValid({ rowData: newRow, allowInvalid: true }).valid;
                            if (valid) {
                                addList.push(newRow);
                            }
                        }
                        else if (type == 'update') {
                            var valid = grid.isValid({ rowData: rowData, allowInvalid: true }).valid;
                            if (valid) {
                                if (rowData[recIndx] == null) {
                                    addList.push(rowData);
                                }
                                else {
                                    updateList.push(rowData);
                                }
                            }
                        }
                        else if (type == 'delete') {
                            if (rowData[recIndx] != null) {
                                deleteList.push(rowData);
                            }
                        }
                    }
                   
                    if (addList.length || updateList.length || deleteList.length) {

                        var passBack = JSON.stringify({
                            addList: addList,
                            updateList: updateList,
                            deleteList: deleteList
                        });

                        $.ajax({
                            async: true,
                            url: "EquipmentListWS.asmx/BatchGridEQL",
                            type: "POST",
                            dataType: "json",
                            contentType: 'application/json; charset=utf-8',
                            data: JSON.stringify({ list: passBack }),
                            success: function (changes) {
                                var jsonData = JSON.parse(changes.d);
                                //Uncomment following logs for code development
                                console.log(JSON.parse(passBack));
                                console.log(jsonData);

                                //commit the changes
                                grid.commit({ type: 'add', rows: jsonData.addList });
                                grid.commit({ type: 'update', rows: jsonData.updateList });
                                grid.commit({ type: 'delete', rows: jsonData.deleteList });
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                console.log(jqXHR);
                                console.log(textStatus);
                                console.log(errorThrown);
                            }
                        });
                    }
                },

3
I've attached a screenshot the console.log(ui) of my pqGrid when I add a row. On the top you can see what is being sent to the server and on the bottom what is being returned from the server. EquipmentID, Depreciation_Years, and Net_Book_Value are not being sent back to the server. These columns are editable: false because the server auto-assigns or auto-calculates those values. I need to send these columns back to the server or else pqGrid is not updated correctly and leads to another row being added whenever the newly added row is updated. Creating a postback or a refreshDataAndView patches the issue, but that causes the undo/redo buttons to not function.

I have a different pqGrid where the ID is also editable: false and it does not have this issue. The add, update, delete codes are the same for both grids. The only real difference between the two is the column model.

4
I have a pqGrid based off of the Auto Save Demo.

I'm having issues sending non-editable columns to a remote location when adding a row and when updating a newly added row. It only sends the editable columns to the remote location. I need to send back all the columns for primary key ID indexing and accounting calculations. This is not an issue with existing rows. Which setting needs to be added/changed for the grid to always send all of the columns to the remote location?

5
That looks much more straight forward. Is exportData only available on the Pro version?

6
I'm following the Export to Excel demo and I'm having trouble adapting it to my ASP.NET Web Forms project. I'm using an .asmx Web Service for my Web Methods.

I'm getting 500 internal server errors related to the following.

One issue is using two Web Methods with the same name in Web Forms. The POST method will run correctly if the GET method is commented out. With both uncommented, I get the error "Item has already been added. Key in dictionary: 'Excel';  Key being added: 'Excel'."

The other issue is returning the correct file in the GET Method. FileContentResult and "return File(new UTF8Encoding().GetBytes(contents), "text/csv", filename);" doesn't compile in Web Forms because they are MVC.

Here is my Export To Excel code.

JavaScript
Code: [Select]
        toolbar: {
            items: [
                //Export to Excel buttons
                { type: 'button', label: "Export to XML", icon: 'ui-icon-document', listeners:
                        [{ "click": function (evt) {
                                $grid.pqGrid("exportExcel", { url: "EditJobListWS.asmx/Excel", sheetName: "Gird_Export" });
                            }
                        }]
                },
                { type: 'button', label: "Export to CSV", icon: 'ui-icon-document', listeners:
                        [{ "click": function (evt) {
                                $grid.pqGrid("exportCsv", { url: "EditJobListWS.asmx/Excel" });
                            }
                        }]
                }
            ]
        },

ASP.NET C# Web Service (.asmx)
Code: [Select]
        //AJAX POST
        [WebMethod(EnableSession = true)]
        public String Excel(String extension, String excel)
        {
            if (extension != "csv" && extension != "xml") { throw new Exception("Unsupported extension"); }
            String filename = "Grid." + extension;
            Session["ExportExcel"] = excel;
            return filename;
        }

        //AJAX GET
        [WebMethod(EnableSession = true)]
        [ScriptMethod(UseHttpGet = true)]
        public Object Excel(String filename)
        {
            String contents = Session["ExportExcel"].ToString();

            if (filename.EndsWith(".csv"))
            {
                //return File(new UTF8Encoding().GetBytes(contents), "text/csv", filename);
            }
            else if (filename.EndsWith(".xml"))
            {
                //return File(new UTF8Encoding().GetBytes(contents), "text/xml", filename);
            }
            else { throw new Exception("Unknown extension"); }

            return contents;
        }


7
That did the trick! Thank you so much!

8
Help for ParamQuery Grid (free version) / Toolbar Buttons (Auto Save Demo)
« on: September 15, 2017, 09:53:32 pm »
Hello,

I am applying the PQGrid Auto Save Demo to my ASP.NET Web Forms project and I am having issues getting the buttons in the PQGrid toolbar to work. I mainly want to implement adding rows. Undo, Redo, and Export to Excel features are secondary and can come later. The issue seems like the toolbar button "click" event is not firing. Editing the grid, deleting rows, and paging works in my grid. It's only items related to the toolbar.

Here is a jsFiddle of my code. http://jsfiddle.net/pb5kpred/65/

Also, thank you for creating ParamQuery. I'm coming from ASP.NET GridView, so PQGrid is a huge improvement. I'm really enjoying PQGrid so far.

Pages: [1]