nuBrowseRow()
, to make it trivial to grab information about the clicked-on cell (or any other cell in the same row) when you use nuSelectBrowse()
.Key features of
nuBrowseRow()
- Automatic unpacking of primary key, row index, column index, cell HTML, cell text value, and the jQuery cell object
- Optional parameter to pull data for a different column in the same row
- Zero boilerplate—one call instead of half a dozen attribute lookups
Code: Select all
function nuSelectBrowse(event, element) {
const cell = nuBrowseRow(element);
console.log(cell.row);
}
Code: Select all
function nuSelectBrowse(event, element) {
const { pk, row, column, html, value, $cell } = nuBrowseRow(element);
console.log(pk, row, column, html, value, $cell);
}
Code: Select all
function nuSelectBrowse(event, element) {
// Pass zero-based column index (1 = second column)
const otherCell = nuBrowseRow(element, 1);
console.log(otherCell.value);
}
Code: Select all
function nuSelectBrowse(event, element) {
// Pass the column primary key which is more stable than a numeric index
const otherCell = nuBrowseRow(element, 'nu6afd6cb37627eb1'); // data-nu-column-id="nu6afd6cb37627eb1"
console.log(otherCell.value);
}
Before v4.7.x, you’d have to do something like this:
Code: Select all
function nuSelectBrowse(event, element) {
const $cell = $(element);
const pk = $cell.attr('data-nu-primary-key');
const row = $cell.attr('data-nu-row');
const column = $cell.attr('data-nu-column');
const value = $cell.text();
const html = $cell.html();
console.log(pk, row, column, html, value, $cell);
}
Code: Select all
function nuSelectBrowse(event, element) {
const $cell = $(element);
const row = $cell.attr('data-nu-row');
// Build the other cell’s ID: "nucell_<row>_<column>"
const otherCellId = 'nucell_' + row + '_1'; // second column
const $otherCell = $('#' + otherCellId);
const otherCellValue = $otherCell.text();
console.log(otherCellValue);
}