Skip to content

Commit 70f453e

Browse files
authored
Merge pull request #4649 from syncfusion-content/993332-PartialSelection
993332: Partial Selection Sample
2 parents ab804ed + db83758 commit 70f453e

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public IActionResult Index()
2+
{
3+
var tree = TreeData.GetTaskData();
4+
ViewBag.datasource = tree;
5+
return View();
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@(Html.EJS().TreeGrid("PartialSelection")
2+
.EnableVirtualization(true)
3+
.DataSource((IEnumerable<object>)ViewBag.datasource)
4+
.AllowSelection()
5+
.SelectionSettings(sel => sel.PersistSelection(true)).IdMapping("TaskID")
6+
.ParentIdMapping("ParentID").TreeColumnIndex(1).IsRowSelectable("isRowSelectable")
7+
.Columns(col =>
8+
{
9+
col.Type("checkbox").Width(60).Add();
10+
col.Field("Task").HeaderText("Task").Width(300).Add();
11+
col.Field("TaskID").Visible(false).IsPrimaryKey(true).Add();
12+
col.Field("AssignedTo").HeaderText("Assigned To").Width(140).Add();
13+
col.Field("StartDate").HeaderText("Start").Format("yMd").Width(180).Add();
14+
col.Field("DueDate").HeaderText("Due").Format("yMd").Width(180).Add();
15+
col.Field("Priority").HeaderText("Priority").Width(90).Add();
16+
col.Field("Progress").HeaderText("Status").Width(90).Add();
17+
}).Render())
18+
<script>
19+
function isRowSelectable(data,columns) {
20+
return data.Progress !== 'Completed';
21+
}
22+
</script>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource" enableVirtualization="true" allowSelection="true" parentIdMapping="ParentID" idMapping="TaskID" treeColumnIndex="1" isRowSelectable="isRowSelectable">
2+
<e-treegrid-selectionsettings pesistSelection="true"></e-treegrid-selectionsettings>
3+
<e-treegrid-columns>
4+
<e-treegrid-column type="checkbox" width="50"></e-treegrid-column>
5+
<e-treegrid-column field="Task" headerText="Task" width="300"></e-treegrid-column>
6+
<e-treegrid-column field="TaskID" visible="false" isPrimaryKey="true"></e-treegrid-column>
7+
<e-treegrid-column field="AssignedTo" headerText="Assigned To" width="140"></e-treegrid-column>
8+
<e-treegrid-column field="StartDate" headerText="Start" format="yMd" type="date" width="180"></e-treegrid-column>
9+
<e-treegrid-column field="DueDate" headerText="Due" format="yMd" type="date" width="180"></e-treegrid-column>
10+
<e-treegrid-column field="Priority" headerText="Priority" width="90"></e-treegrid-column>
11+
<e-treegrid-column field="Progress" headerText="Status" width="90"></e-treegrid-column>
12+
</e-treegrid-columns>
13+
</ejs-treegrid>
14+
<script>
15+
function isRowSelectable(data,columns) {
16+
return data.Progress !== 'Completed';
17+
}
18+
</script>

ej2-asp-core-mvc/tree-grid/EJ2_ASP.MVC/selection/check-box-selection.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,31 @@ In checkbox selection, selection can also be done by clicking on rows. This sele
7676

7777
> Checkbox Selection feature is intended for row selection only; it is not compatible with cell selection mode.
7878
79+
## Conditional row selection using isRowSelectable
80+
81+
The TreeGrid supports conditional row selection through the [isRowSelectable](https://help.syncfusion.com/cr/cref_files/aspnetcore-js2/Syncfusion.EJ2~Syncfusion.EJ2.TreeGrid.IsRowSelectable.html) property. This feature enables dynamic business logic to determine which rows can be selected, ensuring that only rows meeting specific conditions are selectable. The `isRowSelectable` property accepts a function that evaluates each row’s data and returns **true** to enable selection or **false** to disable it. The function is executed for the entire data source before rendering, making it suitable for scenarios where selection must be restricted based on criteria.
82+
83+
{% if page.publishingplatform == "aspnet-core" %}
84+
85+
{% tabs %}
86+
{% highlight cshtml tabtitle="CSHTML" %}
87+
{% include code-snippet/tree-grid/selection/partial-selection/tagHelper %}
88+
{% endhighlight %}
89+
{% highlight c# tabtitle="Partial.cs" %}
90+
{% include code-snippet/tree-grid/selection/partial-selection/partial.cs %}
91+
{% endhighlight %}
92+
{% endtabs %}
93+
94+
{% elsif page.publishingplatform == "aspnet-mvc" %}
95+
96+
{% tabs %}
97+
{% highlight razor tabtitle="CSHTML" %}
98+
{% include code-snippet/tree-grid/selection/partial-selection/razor %}
99+
{% endhighlight %}
100+
{% highlight c# tabtitle="Partial.cs" %}
101+
{% include code-snippet/tree-grid/selection/partial-selection/partial.cs %}
102+
{% endhighlight %}
103+
{% endtabs %}
104+
{% endif %}
105+
79106
N> You can refer to our [`ASP.NET MVC Tree Grid`](https://www.syncfusion.com/aspnet-mvc-ui-controls/tree-grid) feature tour page for its groundbreaking feature representations. You can also explore our [`ASP.NET MVC Tree Grid example`](https://ej2.syncfusion.com/aspnetmvc/TreeGrid/Overview#/material) to knows how to present and manipulate data.

0 commit comments

Comments
 (0)