Author Topic: Get data of current row in selectChange()  (Read 3705 times)

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Get data of current row in selectChange()
« on: December 21, 2015, 06:25:40 pm »
I want to read the cells value of current selected row in selectChange() event.

I saw and changed the demo in http://paramquery.com/pro/demos/selection_row but I don't know how to read the id or the company of the current row.

Thank you

Code: [Select]
$(function () {

        var data = [
            { id: 1, company: 'Exxon Mobil', revenues: '339938.0', profits: '36130.0' },
            { id: 2, company: 'Wal-Mart Stores', revenues: '315654.0', profits: '11231.0' },
            { id: 3, company: 'Royal Dutch Shell', revenues: '306731.0', profits: '25311.0' },
            { id: 4, company: 'BP', revenues: '267600.0', profits: '22341.0' },
            { id: 5, company: 'General Motors', revenues: '192604.0', profits: '-10567.0' },
            { id: 6, company: 'Chevron', revenues: '189481.0', profits: '14099.0' },
        ];
        var obj = {
            scrollModel: { autoFit: true },
            height: 200,
showBottom: false,
            resizable: true,
            editable: false,
            numberCell: { show: false },
            selectionModel: { type: 'row', fireSelectChange: true },
            swipeModel: { on: false }
        };
        obj.colModel = [
            { title: "ID", width: 100, dataType: "integer", dataIndx: "id" },
            { title: "Company", width: 200, dataType: "string", dataIndx: "company" },
            { title: "Revenues ($ millions)", width: 150, dataType: "float", align: "right", dataIndx: "revenues" },
            { title: "Profits ($ millions)", width: 150, dataType: "float", align: "right", dataIndx: "profits" }
        ];
        obj.dataModel = {
            data: data
        };

        obj.selectChange = function (evt, ui) {
           alert( this.selection().??????? );

           // $("#select_change_div").html(JSON.stringify(address));
        }
       
        var $grid = $("#grid_row_selection").pqGrid(obj);
    });


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Get data of current row in selectChange()
« Reply #1 on: December 21, 2015, 06:50:32 pm »
It can be one or more than one selected row, the below code can be used to get array of id of selected rows.

Code: [Select]
var selected = [],
sel = this.selection({type:'row', method:'getSelection'});

for(var i=0; i< sel.length; i++){
selected.push(sel[ i ].rowData['id']);
}
console.log(selected);

raffoschi

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Get data of current row in selectChange()
« Reply #2 on: December 21, 2015, 07:00:26 pm »
Thank you