I am attempting to use a MVVM grid in a div that is marked as role="dialog" and has the aria-hidden set to true. The div is tied to a button using the data-target attribute on a button. The basic setup of the MVC Razor page is that button is in one div block and the grid is in another div block.
<div class="...." id="view">
<div class="row>
<div class="col-md-3">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myGridDiv" data-bind="click: onMyButtonPressed">View</button>
</div>
......
</div>
</div>
<div class="modal fade" id="myGridDiv" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" data-role="content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">View</h4>
</div>
<div class="modal-body">
<div id="myGrid"
data-role="grid"
data-columns='[
{ field: "Col1", title: "Col 1", width: "15%" },
{ field: "Col2", title: "Col 2", width: "20%"},
{ field: "Col3", title: "Col 3", width: "20%"},
{ field: "Col4", title: "Col 4", width: "15%"},
{ field: "Col5", title: "Col 5", width: "15%"},
{ field: "Col6", title: "Col 6", width: "15%" } ]'
data-bind="source: myGridDataSource, visible: true">
</div>
</div>
</div>
</div>
</div>
@section scripts
{
var myGridDataSource = new kendo.data.DataSource({
transport: {
read: {
async: false,
url: '/api/GridData/GetData?id=1',
dataType: "json"
},
},
serverPaging: true,
pageSize: 10,
filter: { field: "Id", operator: "eq", value: 1 },
schema: {
model: { id: "Id" },
total: function(data) {
return data.length;
}
},
error: function(result) {
alert(result);
}
});
var myModel = kendo.observable({
isVisible: false,
isEnabled: false,
dataSource: myGridDataSource,
onViewHistoryButtonPressed: function (e) {
var grid = $('#myGrid').data("kendoGrid");
if (null != grid) {
grid.dataSource.read();
grid.refresh();
} else {
console.log("failed to find grid");
}
}
});
kendo.bind($("#view"), myModel);
}
So the probably I am running into is that the above does not seem to populate the grid with any data. When I click the button I see it hit my click method and the dialog does display, but there is not grid data being displayed. The grid does not even attempt to hit my WebApi controller.
I am not sure what I am doing wrong on this since I have been able to use this same grid logic on other pages without issue. The only difference here is that the grid is being displayed in a dialog and must be refreshed each time the dialog is loaded.
<div class="...." id="view">
<div class="row>
<div class="col-md-3">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myGridDiv" data-bind="click: onMyButtonPressed">View</button>
</div>
......
</div>
</div>
<div class="modal fade" id="myGridDiv" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content" data-role="content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">View</h4>
</div>
<div class="modal-body">
<div id="myGrid"
data-role="grid"
data-columns='[
{ field: "Col1", title: "Col 1", width: "15%" },
{ field: "Col2", title: "Col 2", width: "20%"},
{ field: "Col3", title: "Col 3", width: "20%"},
{ field: "Col4", title: "Col 4", width: "15%"},
{ field: "Col5", title: "Col 5", width: "15%"},
{ field: "Col6", title: "Col 6", width: "15%" } ]'
data-bind="source: myGridDataSource, visible: true">
</div>
</div>
</div>
</div>
</div>
@section scripts
{
var myGridDataSource = new kendo.data.DataSource({
transport: {
read: {
async: false,
url: '/api/GridData/GetData?id=1',
dataType: "json"
},
},
serverPaging: true,
pageSize: 10,
filter: { field: "Id", operator: "eq", value: 1 },
schema: {
model: { id: "Id" },
total: function(data) {
return data.length;
}
},
error: function(result) {
alert(result);
}
});
var myModel = kendo.observable({
isVisible: false,
isEnabled: false,
dataSource: myGridDataSource,
onViewHistoryButtonPressed: function (e) {
var grid = $('#myGrid').data("kendoGrid");
if (null != grid) {
grid.dataSource.read();
grid.refresh();
} else {
console.log("failed to find grid");
}
}
});
kendo.bind($("#view"), myModel);
}
So the probably I am running into is that the above does not seem to populate the grid with any data. When I click the button I see it hit my click method and the dialog does display, but there is not grid data being displayed. The grid does not even attempt to hit my WebApi controller.
I am not sure what I am doing wrong on this since I have been able to use this same grid logic on other pages without issue. The only difference here is that the grid is being displayed in a dialog and must be refreshed each time the dialog is loaded.