Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
Cannot get rowSelection (or other things) to work
posted

I have and igGrid and am trying to find use right way of getting the selected row(s), its index, and values of cells in that row. My GRID has this features :

                features: [{
                    name: "RowSelectors",
                        enableCheckBoxes: false,
                        enableRowNumbering: true
                    },{
                       name: "Selection",
                        mode: "row",
                        multipleSelection: false
                        //rowSelectionChanged:rowSelection
                    },{
                        name: "Sorting",
                        firstSortDirection: "ascending",
                        type: "local"                    
                    }]


I went to this site example : http://www.igniteui.com/grid/grid-api-events and copied this code exactly :

    var rows = $("#grid").igGridSelection("selectedRows");
    apiViewer.log("The number of selected rows is: " + rows.length);
    $.each(rows, function (i, val) {
        apiViewer.log("Row with index " + val.index + " is selected");
    });


and it doesnt work at all. I tried many things :

    //var idx = document.getElementById("rsGrid")._selectedRow.index;           // _selected_row undefined
    //var idx = $("#rsGrid")._selectedRow.index;                                            // _selected_row undefined

    var rows = $("#grid").igGridSelection("selectedRows");                      // works??
    $.each(rows, function (i, val) {
        var aa = "Row with index " + val.index + " is selected";                // val.index is undefined
        var cc = "Row with index " + val.index() + " is selected";              //  'index' is not a function
        var ID = $("#rsGrid").getCellValue(val.index, "idField");               // fails
    });

Other things that do NOT work :

        var rows = $("#rsGrid").igGridSelection("selectedRows");
        if ( rows.length != 1 ) { }                                                   // rows.length is ALWAYS 1

        $('#rsGrid').igGridSelection('clearSelection');                        // does NOT clear the selection


The ONLY thing I could get to work is this :

        var grid = $("#rsGrid").data("igGrid");
        var idx  = grid._selectedRow.index;
        var ID   = grid.getCellValue(grid._selectedRow.index, "idField");

which is not the right way of coding it, as it uses an undocumented attribute and will NOT work for a multiple selection grid.

What am I doing wrong and why doesnt this work??

Thank you.