Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SlickGrid callback onRowSelect?

I want to add a callback when the user selects a row in the table, but I can't figure out how to do so...

Here's what I have so far:

    <script src="/js/jquery-1.4.2.min.js"></script>
    <script src="jquery-ui-1.8.8.custom.min.js"></script>
    <script src="jquery.event.drag.2.0.min.js"></script>
    <script src="slick.core.js"></script>
    <script src="slick.rowselectionmodel.js"></script>
    <script src="slick.grid.js"></script>
    <script>
        var grid;
        var columns = [ /* my column definitons */ ];
        var options = {
            enableCellNavigation: true,
            enableColumnReorder: false,
            enableAddRow: true
        };

        $(function() {
            $.getJSON('/actions/unit_list.php', function (data) {
                grid = new Slick.Grid("#myGrid", data, columns, options);
                grid.setSelectionModel(new Slick.RowSelectionModel());
                $('#myGrid').show();
            });
        });
    </script>

With this, I can select the row (as per this example), but I've no idea how to add a callback when the rows are selected (preferably something that returns the row id(s), since I want to use those to load something else on the page).

Can anyone help me with this?

like image 997
neezer Avatar asked Dec 19 '25 17:12

neezer


1 Answers

Ahh, after reviewing more of the code on example 6--specifically the interaction of the remotemodel--I see that I have to call the triggered function like this:

grid.onSelectedRowsChanged.subscribe(function() { console.log(grid.getSelectedRows()); });

From here, I can use grid.getSelectedRows() to return the selected rows, as @Tin pointed out.

like image 194
neezer Avatar answered Dec 21 '25 10:12

neezer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!