Skip to content

Commit ab804ed

Browse files
Merge pull request #4654 from syncfusion-content/989596-selection-dev
989596: Included partial selection topic - Development
2 parents 13ec86f + 15a3a5e commit ab804ed

File tree

5 files changed

+75
-0
lines changed

5 files changed

+75
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public IActionResult Index()
2+
{
3+
ViewBag.dataSource = OrderDetails.GetAllRecords();
4+
return View();
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Html.EJS().Grid("grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col =>
2+
{
3+
col.Type("checkbox").Width("40").Add();
4+
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("110").ValidationRules(new { required = true }).Add();
5+
col.Field("CustomerName").HeaderText("Customer Name").Width("120").ValidationRules(new { required = true }).Add();
6+
col.Field("Product").HeaderText("Product").Width("110").EditType("dropdownedit").Add();
7+
col.Field("Amount").HeaderText("Amount").Width("110").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).ValidationRules(new { required = true }).Add();
8+
col.Field("OrderDate").HeaderText("Order Date").Width("110").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).EditType("datepickeredit").Format("yMd").Add();
9+
col.Field("Status").HeaderText("Status").Width("110").EditType("dropdownedit").Add();
10+
}).AllowPaging().AllowSorting().AllowFiltering().Toolbar(new List<string>() { "Edit", "Update", "Cancel" }).FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Excel)).EditSettings(edit => {edit.AllowEditing(true).AllowAdding(false).AllowDeleting(false).Mode(Syncfusion.EJ2.Grids.EditMode.Normal);}).SelectionSettings(select => select.PersistSelection(true)).IsRowSelectable("isRowSelectable").Render()
11+
<script>
12+
function isRowSelectable(data, columns) {
13+
return data.Status !== 'Cancelled';
14+
}
15+
</script>
16+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<ejs-grid id="grid" dataSource="@ViewBag.dataSource" allowPaging="true" allowSorting="true" allowFiltering="true" toolbar="@(new List<string>() { "Edit", "Update", "Cancel" })" isRowSelectable="isRowSelectable">
2+
<e-grid-selectionSettings persistSelection="true"></e-grid-selectionSettings>
3+
<e-grid-filterSettings type="Excel"></e-grid-filterSettings>
4+
<e-grid-editSettings allowEditing="true" allowAdding="false" allowDeleting="false"></e-grid-editSettings>
5+
<e-grid-columns>
6+
<e-grid-column type="checkbox" width="40"></e-grid-column>
7+
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="110" validationRules="@(new { required = true })"></e-grid-column>
8+
<e-grid-column field="CustomerName" headerText="Customer Name" width="120" validationRules="@(new { required = true })"></e-grid-column>
9+
<e-grid-column field="Product" headerText="Product" width="110" editType="dropdownedit"></e-grid-column>
10+
<e-grid-column field="Amount" headerText="Amount" width="110" format="C2" textAlign="Right" validationRules="@(new { required = true })"></e-grid-column>
11+
<e-grid-column field="OrderDate" headerText="Order Date" width="110" textAlign="Right" editType="datepickeredit" format="yMd"></e-grid-column>
12+
<e-grid-column field="Status" headerText="Status" width="110" editType="dropdownedit"></e-grid-column>
13+
</e-grid-columns>
14+
</ejs-grid>
15+
16+
<script>
17+
function isRowSelectable(data, columns) {
18+
return data.Status !== 'Cancelled';
19+
}
20+
</script>

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ In the following sample, the selection of specific rows has been prevented based
8888

8989
![Prevent specific rows from being selected in checkbox selection](../images/selection/checkbox-prevent.gif)
9090

91+
## Partial selection using isRowSelectable
92+
93+
The `isRowSelectable` callback in Syncfusion's EJ2 Grid allows control over which rows users can select. It uses a simple callback that runs before the grid loads the data. This callback checks each row data and returns **true** if the row can be selected, or **false** for non-selectable rows.
94+
95+
For local data, the callback checks all items just once when the grid first loads. For remote data, it only checks the rows shown on the current page when the grid first appears. It re-checks them every time an action occurs, such as changing pages, filtering, or sorting.
96+
97+
In the example below, it prevents selection of rows with canceled orders.
98+
99+
{% tabs %}
100+
{% highlight cshtml tabtitle="CSHTML" %}
101+
{% include code-snippet/grid/selection/prevent-checkbox-selection/razor %}
102+
{% endhighlight %}
103+
{% highlight c# tabtitle="checkbox.cs" %}
104+
{% include code-snippet/grid/selection/prevent-checkbox-selection/checkbox.cs %}
105+
{% endhighlight %}
106+
{% endtabs %}
107+
91108
## How to select single row in checkbox selection mode
92109

93110
The ASP.NET MVC Grid allows you to select only one row at a time within the Grid. This feature is particularly useful when you want to ensure that only a single row is selected, and any previous selections are cleared when a new row is selected.

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ In the following sample, the selection of specific rows has been prevented based
8888

8989
![Prevent specific rows from being selected in checkbox selection](../images/selection/checkbox-prevent.gif)
9090

91+
## Partial selection using isRowSelectable
92+
93+
The `isRowSelectable` callback in Syncfusion's EJ2 Grid allows control over which rows users can select. It uses a simple callback that runs before the grid loads the data. This callback checks each row data and returns **true** if the row can be selected, or **false** for non-selectable rows.
94+
95+
For local data, the callback checks all items just once when the grid first loads. For remote data, it only checks the rows shown on the current page when the grid first appears. It re-checks them every time an action occurs, such as changing pages, filtering, or sorting.
96+
97+
In the example below, it prevents selection of rows with canceled orders.
98+
99+
{% tabs %}
100+
{% highlight cshtml tabtitle="CSHTML" %}
101+
{% include code-snippet/grid/selection/prevent-checkbox-selection/tagHelper %}
102+
{% endhighlight %}
103+
{% highlight c# tabtitle="checkbox.cs" %}
104+
{% include code-snippet/grid/selection/prevent-checkbox-selection/checkbox.cs %}
105+
{% endhighlight %}
106+
{% endtabs %}
107+
91108
## How to select single row in checkbox selection mode
92109

93110
The ASP.NET CORE Grid allows you to select only one row at a time within the Grid. This feature is particularly useful when you want to ensure that only a single row is selected, and any previous selections are cleared when a new row is selected.

0 commit comments

Comments
 (0)