SlickGrid callback onRowSelect?

若如初见. 提交于 2019-12-11 02:12:41

问题


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?


回答1:


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.




回答2:


You can get selected rows by calling grid.getSelectedRows().



来源:https://stackoverflow.com/questions/4732115/slickgrid-callback-onrowselect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!