When trying to access my grid from Javascript code, I seem to have made mistakes. Can you help me locate them?
This is the Grid code I am using:
<div id="kendoo">
@(Html.Kendo().Grid<SalePortal.ServiceReference.Product>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(product => product.pID).Title("Product ID");
columns.Bound(product => product.productName).Title("Product Name");
columns.Bound(product => product.productPrice).Title("Price");
columns.Command(command => command.Custom("Buy").Click("Sale"));
})
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Read(read => read.Action("GetProduct","Home"))
)
)
</div>
And here is my javascript snippet:
<script type="text/javascript">
function Sale(e)
{
var grid = $("#kendoo").data("kendoGrid");
var myvar = grid.dataItem($(this).closest("tr"));
alert(my.pID);
var url = "@Url.Action("Sale", "Home")";
$.ajax({
url: url,
type: 'POST',
data: { cID: 1, pID: prID },
});
}
</script>
Upon runningthe website, the variable grid
in the Javascript section appears as "undefined". This leads to an error message:
"Javascript runtime error: dataItem of undefined or null reference"
It seems that due to the undefined status of the grid, this error arises. What steps can be taken to rectify this issue so I can successfully access the selected row cell?