@(Html.EJS().TreeGrid("TreeGrid")
…………………. . .
.QueryCellInfo("onquerycellInfo")
.Render())
………………. .. .
<script>
function onquerycellInfo(args) {
if (args.data['check'] == 1 && args.column.field == "orderName") {
var checkstate = args.cell.querySelectorAll(".e-hierarchycheckbox")[0].children[1] // get the checkbox class here
checkstate.classList.add("e-check") // add the e-check class to the specific cell satisfying the condition
}
}
</script> |
<button onclick="selectcheckbox()">selectcheckbox</button>
………………… . .
function selectcheckbox() {
var treegridinstance = document.getElementsByClassName("e-treegrid")[0].ej2_instances[0] //take treegrid instance here
treegridinstance.selectCheckboxes([2,3,6]) //call method here
}
|
@(Html.EJS().TreeGrid("TreeGrid")
………………………….
.RowDataBound("onrowDataBound")
.DataBound("databound")
.Render())
………………………..
<script>
var index = [];
var parentID;
function onrowDataBound(args) {
if (args.data['check'] == 1 ) {
if (args.data.hasChildRecords) { //check whether the parent record has a value check == 1
parentID = args.data.ID;
index.push(parseInt(args.row.getAttribute("aria-rowindex")));
} else if (args.data.parentItem && parentID !== args.data.parentItem.ID) {
index.push(parseInt(args.row.getAttribute("aria-rowindex")));
}
}
}
function databound(args) {
var treegridinstance = document.getElementsByClassName("e-treegrid")[0].ej2_instances[0]; //take treegrid instance here
treegridinstance.selectCheckboxes(index);
}
</script>
|
@(Html.EJS().TreeGrid("TreeGrid")
……………………………… . .
.Columns(col =>
{ col.Field("orderName").ShowCheckbox(true).HeaderText("orderName").AllowEditing(false).Width("100").Add();
col.Field("country").HeaderText("country").Edit(new { create = "create", read = "read", destroy = "destroy", write = "write" }).Width("100").Add();
})
.Render())
<script>
……………………. .
var multiselect;
…………………. . .
function read() {
return multiselect.text; //return the text to show the countryname
}
function write(args) {
multiselect = new ej.dropdowns.MultiSelect({
dataSource: @Html.Raw(Json.Encode(@ViewBag.comboData)),
fields: { text: 'text', value: 'value' },
placeholder: "Válasszon országot",
value: args.rowData[args.column.field] ? args.rowData[args.column.field].split(',') : null,
mode: 'CheckBox'
});
multiselect.appendTo(elem);
}</script> |
@(Html.EJS().TreeGrid("TreeGrid")
……………………………… . .
.Columns(col =>
{
…………………..
})
.Render())
<script>
……………………. .
var multiselect;
…………………. . .
function read() {
return multiselect.value; //return the value to show the ID
}
function write(args) {
multiselect = new ej.dropdowns.MultiSelect({
dataSource: @Html.Raw(Json.Encode(@ViewBag.comboData)),
fields: { text: 'text', value: 'value' },
placeholder: "Válasszon országot",
value: args.rowData[args.column.field] ? args.rowData[args.column.field].split(',') : null,
mode: 'CheckBox'
});
multiselect.appendTo(elem);
}
</script>
|
@(Html.EJS().TreeGrid("TreeGrid")
DataSource(dataManager =>
{
dataManager
.Url(@Url.Action("Datasource", "TreeGrid"))
.UpdateUrl(@Url.Action("Update", "TreeGrid"))
.Adaptor("UrlAdaptor");
}) .Columns(col =>
{
………..
})
.IdMapping("TaskId").ParentIdMapping("ParentId")
.AutoCheckHierarchy(true)
.TreeColumnIndex(0)
.Render()) |
@(Html.EJS().TreeGrid("TreeGrid")
DataSource(dataManager =>
{
dataManager
.Url(@Url.Action("Datasource", "TreeGrid"))
.UpdateUrl(@Url.Action("Update", "TreeGrid"))
.Adaptor("UrlAdaptor");
}) .Columns(col =>
{
………..
})
.IdMapping("TaskId").ParentIdMapping("ParentId")
.AutoCheckHierarchy(true)
.TreeColumnIndex(0)
.Render()) |
Hi Gowri,
Thank You for Your Help!
Regards, László
@(Html.EJS().TreeGrid("TreeGrid")
………………. . .
.Columns(col =>
{
……………. . .
})
.LoadChildOnDemand(true) //to access child records at initial render
.RowDataBound("onrowDataBound")
.DataBound("databound")
.Render())
function databound(args) {
var treegridinstance = document.getElementsByClassName("e-treegrid")[0].ej2_instances[0];
treegridinstance.collapseAll(); //call collapseAll method to collapse parent records at initial render
}
Server side code for LoadChildOnDemand
public ActionResult UrlDatasource(DataManagerRequest dm)
{
if (dm.Where != null)
{
DataSource = CollectChildRecords(DataSource, dm);
}
}
public IEnumerable CollectChildRecords(IEnumerable datasource, DataManagerRequest dm)
{
DataOperations operation = new DataOperations();
IEnumerable DataSource = treeData; // use the total DataSource here
string IdMapping = "ID";// define your IdMapping field name here
int[] Ids = new int[0];
foreach (var rec in datasource)
{
int ID = (int)rec.GetType().GetProperty(IdMapping).GetValue(rec);
Ids = Ids.Concat(new int[] { ID }).ToArray();
}
IEnumerable ChildRecords = null;
foreach (int id in Ids)
{
dm.Where[0].value = id;
IEnumerable records = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
ChildRecords = ChildRecords == null || (ChildRecords.AsQueryable().Count() == 0) ? records : ((IEnumerable<object>)ChildRecords).Concat((IEnumerable<object>)records);
}
if (ChildRecords != null)
{
ChildRecords = CollectChildRecords(ChildRecords, dm);
if (dm.Sorted != null && dm.Sorted.Count > 0)
{
ChildRecords = operation.PerformSorting(ChildRecords, dm.Sorted);
}
datasource = ((IEnumerable<object>)datasource).Concat((IEnumerable<object>)ChildRecords);
}
return datasource;
}
|