如何在SlickGrid中返回特定的单元格值? [英] How do I return a specific cell value in SlickGrid?

查看:127
本文介绍了如何在SlickGrid中返回特定的单元格值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我来说,我似乎无法在SlickGrid中返回特定的单元格值.在此处上有一个示例.但这也不起作用.我以SlickGrid教程#7为例.我要做的就是将click事件添加到返回该单元格值的单元格中.

For the life of me I can't seem to return a specific cell value in SlickGrid. There is an example on SO here. But this did not work either. I am using the SlickGrid tutorial #7 as my example. All I am trying to do is add a click event to a cell that returns that cells value.

注意:我正在通过JSON请求加载数据,并且一切正常.我的click事件触发,但是值未定义.为简便起见,我将省略网格列和选项代码.这是代码,谢谢.所有这一切都是一个很棒的网格.

Note: I am loading my data via JSON request and all works well. 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;
                }
            }

        });
    });

推荐答案

您快到了,应该使用data [row] .fieldname.您的数据中是否有一个名为字段"的字段?

You are almost there, you should use data[row].fieldname. Do you have a field in your data called "field"?

这篇关于如何在SlickGrid中返回特定的单元格值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆