Author Topic: Get value from cell picklist  (Read 3977 times)

noctrona

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 82
    • View Profile
Get value from cell picklist
« on: March 14, 2014, 01:45:13 pm »
Hi,

I use free version before. And I replace it with pro version today. Then I met a problem with my original codes.
I checked pro API about the "editor" option.  Then I try to display a pick list in a cell. Please have a look with the following codes:

Code: [Select]
{ title: "Product", width: 152, dataIndx: "product",
   editor:{
       type: function(ui){ 
           dropDownEditor(ui, productList);                 
       },
       getData: function(ui) {
           saveProduct(ui);
       }
   }
},
{ title: "ProductID", width: 70, dataType: "string",align: "center", dataIndx: "productId",hidden:false,editable: false}

Generate a pick list, my data is a id-name list, so I set Id as option value and name as display name:
Code: [Select]
function dropDownEditor(ui, arr) {
        var $cell = ui.$cell,
            rowData = ui.rowData,
            dataIndx = ui.dataIndx,
            width = ui.column.width,
            cls = ui.cls;
        var dc = $j.trim(rowData[dataIndx]);
       
        var str = "";
        for (var i = 0; i < arr.length; i++) {
                if (dc == arr[i])
                    str += "<option data-id='" + arr[i].Id + "' selected>" + arr[i].Name + "</option>";
                else
                    str += "<option data-id='" + arr[i].Id + "' >" + arr[i].Name + "</option>";
        }
        var $sel = $j("<select style='width:150px;' onchange='chooseProduct()'>" + str + "</select>").appendTo($cell);
}

By the above codes, I can generate a picklist in my cell just like free version. Then when I select on value from pick list I will get this value and name, set value in my "productId" cell and set name in "product" cell.
Code: [Select]
    function saveProduct(ui){
        var $cell = ui.$cell;
        var DM = $j("#grid_json").pqGrid("option", "dataModel");
        var gridData = DM.data;
        gridData[ui.rowIndx]['productId'] = $cell.children().find('option:selected').attr('data-id');
        $j("#grid_json").pqGrid( "refreshCell", { rowIndx: ui.rowIndx, dataIndx: 'productId' } );
        return $cell.children().val();
    }

The problem is I can get id and name, and can set id to "productId" cell, but I can't set product name in "product" cell.
So do you know why this happened?


Thank you!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Get value from cell picklist
« Reply #1 on: March 15, 2014, 09:51:57 pm »
try this :

Code: [Select]
     
   getData: saveProduct