I have a slickgrid with inline filtering (using DataView). I've assigned unique ID to each row of data and I pass this ID (not the row number) to a function which updates a div someplace else on the UI.
This works fine if I don't filter. But if I filter the column prior to passing the ID, it changes the ID to reflect the row #. It will even change a string ID to a row number.
That just seems weird. Any idea what's going on???
grid_msc.onClick.subscribe(function(e, args) {
var cell = grid_msc.getCellFromEvent(e);
var row = cell.row; // get row #
var row_ID = data_msc[row].id; // get the row ID, not row #
var msc = data_msc[args.row][grid_msc.getColumns()[args.cell].field];
alert("Row#:"+row+", RowID:"+row_ID+", Value:"+msc);
mscToUI(msc, row_ID);
});
// Add the selected item to the UI
function mscToUI(addC, cellNum) {
alert(addC+", "+cellNum);
$('#selectedMsc').append('<a href="javascript:removemsc('+cellNum+')" id="'+cellNum+'" class="rSel"><img src="images/remove.png" align="texttop" border="0" style="padding-right:4px;">'+addC+'<br /></a>');
}
})
If you're already using DataView then you should be getting the rows/data from it (dataView_msc
), rather than the original data source (data_msc
).
grid_msc.onClick.subscribe(function(e, args) {
var cell = grid_msc.getCellFromEvent(e); // get the cell
var row = cell.row; // get the row's index (this value will change on filter/sort)
var item = dataView_msc.getItem(row); // get the row's item (see: object, data)
var msc = item[grid_msc.getColumns()[cell.cell].field]; // get the value of the cell
alert("Row Index:"+row+", RowID:"+item.id+", Cell Value:"+msc);
console.log(item);
mscToUI(msc, item.id);
});
I'm not quite sure what you're planning on doing inside mscToUI()
with value of the clicked cell and the value of its row's id
property. I think it might be smarter to simply pass the row's entire data object (item
) to the function and preform any other operations using the DataView's lookup methods:
getIdxById(id)
- With the item's id, find the relative row index in the grid` getItem(i)
- With the row index of the filtered grid, return the data/item for said rowgetItemById(id)
- With the item's id, return the data/item for said itemgetItemByIdx(i)
- With the row index of the unfiltered grid, return the data/item for said rowIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With