简体   繁体   English

如何在SlickGrid中返回特定的单元格值?

[英]How do I return a specific cell value in SlickGrid?

For the life of me I can't seem to return a specific cell value in SlickGrid. 对于我的生活,我似乎无法在SlickGrid中返回特定的单元格值。 There is an example on SO here. 这里有一个关于SO的例子 But this did not work either. 但这也不起作用。 I am using the SlickGrid tutorial #7 as my example. 我使用SlickGrid教程#7作为我的例子。 All I am trying to do is add a click event to a cell that returns that cells value. 我要做的就是将一个click事件添加到返回该单元格值的单元格中。

Note: I am loading my data via JSON request and all works well. 注意:我正在通过JSON请求加载我的数据,一切正常。 My click event fires but the value is undefined. 我的点击事件触发,但值未定义。 For brevity sake I will omit my grid columns and options code. 为简洁起见,我将省略我的网格列和选项代码。 Here is the code and thanks. 这是代码和谢谢。 All and all this is a great grid. 所有这一切都很棒。

var sortcol = "id";
    var sortdir = -1;
    $(function () {
        $.getJSON(baseURL() + 'programs', function (data) {
            dataView = new Slick.Data.DataView();
            grid = new Slick.Grid($("#program-grid"), data, programColumns, programOptions);

            grid.onSort = function (sortCol, sortAsc) {
                sortdir = sortAsc ? 1 : -1;
                sortcol = sortCol.field;

                if (sortAsc == true) {
                    data.sort(compare);
                }
                else {
                    data.reverse(compare);
                }
                grid.render();
            };
            grid.onClick = function (e, row, cell) {
                if (programColumns[cell].id == "id") {
                    var x = data[row][cell].field;//This is where I am stuck
                    window.location.href = "http://google.com/" + x;
                }
            }

        });
    });

You are almost there, you should use data[row].fieldname. 你几乎就在那里,你应该使用数据[row] .fieldname。 Do you have a field in your data called "field"? 您的数据中是否有一个名为“field”的字段?

If you're using dataView, it's simple: 如果您使用的是dataView,那很简单:

// Get the object containing row and cell index of a clicked row.
var gridObject = roundGrid.getCellFromEvent(e); 

var row = gridObject.row; // get selected row index
var row_values = roundDataView.getItem(row); // get the row object 

// Get the actual value.
var cellValue = row_values[roundGrid.getColumns()[gridObject.cell].field]; 

Bind to the onCellChange event 绑定到onCellChange事件

grid.onCellChange.subscribe( function( e, args ) {

    console.log( args.item[ grid.getColumns()[ args.cell ].field ] );

} );

Returns 返回

"{some value}" etc. "This is the newly changed value" “{some value}”等“这是新改变的值”

Docs 文件

onCellChange ({ row: number, cell: number, item: any }) onCellChange ({ row: number, cell: number, item: any })

Grid Events (onCellChange) 网格事件(onCellChange)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM