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.
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(pare);
}
else {
data.reverse(pare);
}
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 = "/" + x;
}
}
});
});
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.
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(pare);
}
else {
data.reverse(pare);
}
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./" + x;
}
}
});
});
Share
Improve this question
edited May 23, 2017 at 12:32
CommunityBot
11 silver badge
asked Jan 22, 2011 at 17:16
trevorctrevorc
3,0316 gold badges33 silver badges50 bronze badges
3 Answers
Reset to default 4You are almost there, you should use data[row].fieldname. Do you have a field in your data called "field"?
If you're using dataView, it's simple:
// 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
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"
Docs
onCellChange ({ row: number, cell: number, item: any })
Grid Events (onCellChange)
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745101423a4611295.html
评论列表(0条)