var grid = $('#DaGrid').data('tGrid');grid.refresh( { searchfilter: search } );public ActionResult Select_archief(string searchfilter) {....}@(Html.Kendo().TreeView()
.Name("CollectionsheetTree")
.DataSource(dataSource => dataSource
.Read(read => read
.Action("_getProjectCollectionsheetTree2", "Project", new { projectId = _projectId }) )
)
.HtmlAttributes(new { style = "height: 200px; overflow: auto; " })
.DragAndDrop(!Model.IsReadOnly)
)
$(document).ready(function () {
var treeView = $("#CollectionsheetTree").data("kendoTreeView");
treeView.find(".k-in").each(function() {
var element = $(this),
data = element.find('> .data');
if (data.length) {
//element.css('background-color', '#aabbcc' );
element.addClass("treeviewNode");
data.remove();
}
});
});
But the execution fails over on this line:
treeView.find(".k-in").each(function() {
The error message says:
Microsoft JScript runtime error: Unable to get value of the property 'find': object is null or undefined
I think it is because when the $(document).ready is executed the treeview is still being constructed.
On the Telerik treeview control there is a OnDataBound event that can be used to ensure that a function is run only after the treeview has been fully initialised.
How can I ensure that the Kendo treeview has been initialised before calling the styling function on it?
For completeness, here is the controller method:
public ActionResult _getProjectCollectionsheetTree2(kendoTreeviewItem node, int? projectId)
{
var nodes = new List<kendoTreeviewItem>();
List<DofSurvey> list;
_dofSurvey.EnrolInUnitOfWork(_unitOfWork);
int collectionSheetId;
int.TryParse(node.id, out collectionSheetId);
if (node.id == null)
{
list = _dofSurvey.FindBy(f => f.ParentSurveyId == null & f.ProjectId == projectId, "Survey").ToList();
}
else
{
list = _dofSurvey.FindBy(f => f.ParentSurveyId == collectionSheetId & f.ProjectId == projectId, "Survey").ToList();
}
list.ForEach(cs =>
{
var d = new kendoTreeviewItem
{
id = cs.SurveyId.ToString(),
text = cs.Survey.Title + "<span class='data'></span>",
hasChildren = cs.ChildSurveys.Any()
};
nodes.Add(d);
});
return Json(nodes, JsonRequestBehavior.AllowGet);
}
I am having issues with populating a telerik dropdown list using jquery. I get the following Error:
'get(...).options' is null or not an object
On line:
$("#courseID").get(0).options.length = 0;
Here is my telerik dropdown list:
<%= Html.Telerik().DropDownList()
.Name("courseID")
.HtmlAttributes(new{ @id="courseID"})
%>
Here is how I am trying to populate it using jquery:
I call the populateDDL function on "StudentID" focusout event, here is the function.
function populateDDL() {
var link = '/Student/EnrollerCourse';
$.ajax({
type: 'POST',
url: link,
data: { id: $('#StudentId').val() },
dataType: 'json',
success: function (result) {
$("#courseID").get(0).options.length = 0;
$("#courseID").get(0).options[0] = new Option("Select", "Select");
$.each(result.courseID, function (item, value) {
var courseID = value;
$("#courseID").get(0).options[$("#courseID").get(0).options.length] = new Option(courseID);
});
},
error: function (result) {
alert("Failed")
}
});
}
var sampleCustomFieldObj = { customfields: [ {columnName: "customField1",type:"number", displayName: "My Number Field"},{columnName: "customField2",type:"string", displayName: "My String Field"},{columnName: "customField3",type:"date", displayName: "My Date Field"}] };function
initControls() {
$(
"#ChargesGrid").kendoGrid({
dataSource: {
type:
"json",
transport: {
read: {
url:
"Charge/GetCharges",
dataType:
"json",
type:
"POST"
}
},
pageSize: 5
},
groupable:
false,
sortable:
true,
pageable: {
refresh:
false,
pageSizes:
true
},
columns: [
{ field:
"Description", title: resourcesSet.str_Desc, width: "150px" },
{ field:
"Amount_Due", title: resourcesSet.str_AmtDue, width: "50px" },
{ field:
"Date", title: resourcesSet.str_Date, width: "50px" },
{ field:
"Title", title: resourcesSet.str_Title, width: "150px" },
{ command: { text:
"Edit", click: showForm }, title: " ", width: "80px"}]
});
}
This is my html rendering the grid
<table id="ChargesGrid"></table>