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.

Parents
  • 5513
    Suggested Answer
    Offline posted

    Hello,

    In order to obtain the selected row when multiple selection is disabled you have to use the selectedRow method:

    $("#grid").igGridSelection("selectedRow");

    If you enable multiple selection then the correct method to use will be selectedRows.

    In the former case you'll get an object which will contain the row element selected, its ID if you have a primary key defined and its index. You can then use it to call getCellValue. As it is a public method you don't need to get the grid instance to use it. Instead you could do:

    $("#grid").igGrid("getCellValue", <row id / row index>, <col key>);

    Please, refer to the API documentation for more information regarding these functions. It's important to note that getCellValue will always consider the first parameter to be a row ID if you define a primary key for the grid (and index otherwise). 

    I hope this helps! Please, let me know if you have any other questions or concerns!

    Best regards,

    Stamen Stoychev 

Reply Children