Author Topic: saveEditCell error  (Read 3904 times)

RedBully

  • Pro Deluxe
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
saveEditCell error
« on: April 15, 2014, 01:12:37 pm »
Trying to call saveEditCell on change event of a ddl/ select but getting:

Unhandled exception at line 248, column 3 in http://oang.localhost/Scripts/jquery-2.1.0.js
0x800a139e - JavaScript runtime error: cannot call methods on pqGrid prior to initialization; attempted to call method 'saveEditCell'


Though clearly the Grid has been initialised so is this error misleading and hiding the actual issue?

Column definition:

Code: [Select]
{ title: 'FormType', editable: function (ui) { return oa.IsCellEditable(this, ui); },
render: function (ui) { return oa.RenderCell(ui, XPPPPf_PageoptionsFormType); },
width: 200,
dataType: 'multiplechoice',
 editor: { type: function (ui) { return oa.editCell(this, ui, XPPPPf_PageoptionsFormType); }, getData: 'oa.getCellDataForSaving' }
},

oa.editCell is a generic function for handling all cell edit UI:

Code: [Select]
oa.editCell = function (context, ui, arr) {
.
[determine datatype from JSON based on cell cords]
.
if (datatype == constants.PropertyDataType.MultipleChoice) {
 
                       return oa.editMultipleChoiceCell(context, ui, arr);
                   }

oa.editMultipleChoiceCell = function (context, ui, arr) {
 
    oa.log('ParamGrid: Editing MultipleChoice Cell');
 
    var $cell = ui.$cell;
    var data = ui.data;
 
    //this won't work with Pro API
    //var cellData = $.trim(data[ui.rowIndx][ui.colIndx]);
    var cellData = $.trim(ui.rowData[ui.column.dataIndx]);
 
    var str = "";
    for (var i = 0; i < arr.length; i++) {
 
        var label = arr[i].label;
        var value = arr[i].value;
 
        if (cellData == value)
            str += "<option value='" + value + "' selected='selected'>" + label + "</option>";
        else
            str += "<option value='" + value + "'>" + label + "</option>";
    }
    var sel = $("<select style='width: 100%; height: 100%'>" + str + "</select>")
    .appendTo($cell);
    //not working - syntax wrong?
    $(sel).change(function() {
        oa.log('********** selection made');
        //one of these are failing
        $(context).pqGrid("saveEditCell");
        //$(context).pqGrid("quitEditMode");
        executeParaGridSaveCommandSet(null, ui, context);
    });
    }

?

Ta.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: saveEditCell error
« Reply #1 on: April 15, 2014, 05:00:35 pm »
I tested it on my end by passing context (this) to $sel.change, it works fine. you can call both saveEditCell and quitEditMode in $sel.change

Which version of jQuery/ jQueryUI are you using. I can test that in it as well.

Are you losing the current value of context somewhere in the call stack of functions. There is an alternative way of calling pqGrid API which may be helpful to you.

$sel.change(function(evt){
  //this points to select list in change event.
  $(this).closest(".pq-grid").pqGrid("saveEditCell");
});
« Last Edit: April 15, 2014, 05:05:57 pm by paramquery »