I'd like to navigate the row on Kendo-Grid. I have 4 Buttons, First, Previous, Next and Last. When the button is clicked it will highlight the record from the Kendo-Grid. I'm not sure how to achieve this. I can get the row index on click button but I cannot make the Kendo-Grid hight light the row and extract the record to be displayed in text box. here are some piece of my code:
On View
<div>
<button id="reg-view-first" title="First" class="menu-item supplementary-table-menu k-grid-add" onclick="javascript:first();">
<img src="@Url.Content("~/Images/first_16.png")" /></button>
<button id="reg-view-back" title="Back" class="menu-item supplementary-table-menu k-grid-add" onclick="javascript:back();">
<img src="@Url.Content("~/Images/back_16.png")" /></button>
<button id="reg-view-next" title="Next" class="menu-item supplementary-table-menu" onclick="javascript:next();">
<img src="@Url.Content("~/Images/forward_16.png")" /></button>
<button id="reg-view-prev" title="Last" class="menu-item supplementary-table-menu" onclick="javascript:last();">
<img src="@Url.Content("~/Images/last_16.png")" /></button>
</div>
function last() {
var grid = $("#queue-table").data("kendoGrid");
//var rowCount = grid.dataSource.view().length; //on current display.
var rowCount = grid.dataSource.data().length; //Actual record count.
var itemID = grid.dataSource.at(rowCount - 1).ItemID
grid.clearSelection();
var row = $(this).closest("tr");
var dataItem = grid.dataItem(row);
row.addClass("k-state-selected");
//grid.select(itemID);
//alert(itemID);
}
function back() {
var grid = $("#queue-table").data("kendoGrid"); //document.getElementsByName("queue-table");
if (grid != null || grid != "undefined")
{
//get the selected index.
var dataRows = grid.items();
var rowIndex = dataRows.index(grid.select());
//alert(rowIndex);
var dataItem = grid.dataItem(grid.select());
//var itemID = grid.columns[0].field;
var itemID = grid.dataSource.at(1).ItemID;
grid.select("tr[data-uid='" + itemID + "']");
var newRow = dataRows.index(grid.select());
newRow.addClass("k-state-selected");
//assign the new selected index
//var newIndex = 0;
//if (rowIndex > 0)
//{
// newIndex = rowIndex - 1
//}
//alert(newIndex);
}
Im a newbie in Kendo and already spent couple of hours figuring out what to do.
if (grid != null || grid != "undefined")isn't right.grid != "undefined"isn't checking if grid isundefinedbut if it's the string "undefined". You should remove the quote marks. Furthermore, you probably want to check that both conditions are true, not either one, so changing the||to&&is also a good idea. The simplest way to do what you want in thisifisif (grid). This will make sure that grid is neithernullnorundefined. - Shai