@(Html.EJ().Grid<object>("Grid1").Datasource((IEnumerable<object>)ViewBag.data).AllowPaging()
.EditSettings(edit => { edit.AllowAdding().AllowDeleting()
.AllowEditing().EditMode(EditMode.Normal); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();
col.Field("BooleanColumn").HeaderText("Checkbox")
.EditType(EditingType.BooleanEdit).Add();
})) |
|
@(Html.EJ().Grid<object>("Grid1").Datasource((IEnumerable<object>)ViewBag.data)
.AllowPaging().ClientSideEvents(eve => { eve.TemplateRefresh("templateRefresh"); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Employee ID").IsPrimaryKey(true).Width(90).Add();
col.Field("BooleanColumn").HeaderText("First Name").Template("#columnTemplate")
.EditTemplate(et => { et.Create("create").Read("read").Write("write");
}).EditType(EditingType.BooleanEdit).Width(90).Add();
})
)
<script type="text/x-jsrender" id="columnTemplate">
<input type="checkbox" id="Verified" name="Verified" class="checkboxstyle" style="width:30px" />
</script>
<script>
function templateRefresh(args) {
// rendering ej Checkbox in templateRefresh event
$(args.cell).find(".checkboxstyle").ejCheckBox({
size: 'Medium',
showRoundedCorner: true,
checked: args.rowData["BooleanColumn"] //"BooleanColumn" is boolean column's field name
});
}
function create() {
return $("<input class='checkboxstyle'/>");
}
function write(args) {
// rendering ej Checkbox for edit template
args.element.ejCheckBox({
size: 'Medium',
showRoundedCorner: true,
checked: args.rowdata["BooleanColumn"] //"BooleanColumn" is boolean column's field name
});
}
function read(args) {
return args.ejCheckBox("isChecked");
}
</script>
<style>
// applying CSS for the checkbox
.e-chkbox-wrap .e-chk-image.e-checkmark {
color: red;
}
</style> |
@(Html.EJ().Grid<object>("Grid").Datasource((IEnumerable<object>)ViewBag.data)
.AllowPaging().EditSettings(edit => { edit.AllowAdding()
.AllowDeleting().AllowEditing().EditMode(EditMode.Batch); })
.ClientSideEvents(eve => { eve.TemplateRefresh("templateRefresh"); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Employee ID").IsPrimaryKey(true).Add();
col.Field("BooleanColumn").HeaderText("First Name").Visible(false).Add();
col.HeaderText("Checkbox")
.Template("#columnTemplate")
.EditType(EditingType.BooleanEdit).Width(90).Add();
})
)
<script type="text/x-jsrender" id="columnTemplate">
<input type="checkbox" id="Verified" name="Verified" class="checkboxstyle" style="width:30px" />
</script>
<script>
function templateRefresh(args) {
var grid = $('#Grid').data("ejGrid");
$(args.cell).find(".checkboxstyle").ejCheckBox({
size: 'Medium',
showRoundedCorner: true,
checked: args.rowData["BooleanColumn"],
//"BooleanColumn" is boolean column's field name
change: function (args) { // checkbox's change event
var target = args.event.target.closest('tr');
var targetCell = args.event.target.closest('td');
var index = target.rowIndex; // for getting row index
var val = args.isChecked; // value of checkbox
grid.setCellValue(index, "BooleanColumn", val);
// updating BooleanColumn column
targetCell.classList.add('e-updatedtd', 'e-icon', 'e-gupdatenotify');
// added class name to edited checkbox column for notifying that
the particular checkbox is being updated
}
});
}
</script>
<style>
.e-chkbox-wrap .e-chk-image.e-checkmark {
color: red;
}
</style> |
@(Html.EJ().Grid<object>("Grid").Datasource((IEnumerable<object>)ViewBag.data)
-----------
.ClientSideEvents(eve => {
eve.TemplateRefresh("templateRefresh").BatchAdd("batch").BeforeBatchSave("save"); })
.Columns(col =>
{
col.Field("OrderID").HeaderText("Employee ID").IsPrimaryKey(true).Width(90).Add();
col.Field("CustomerID").HeaderText("Employee ID").Width(90).Add();
col.Field("BooleanColumn").HeaderText("First Name").Visible(false).Width(90).Add();
col.HeaderText("Checkbox").Template("#columnTemplate")
.EditType(EditingType.BooleanEdit).Width(90).Add();
})
)
<script>
//BatchAdd event
function batch(args) {
//render ej Checkbox with style customization
args.row.find(".checkboxstyle").ejCheckBox({
size: 'Medium',
showRoundedCorner: true
});
}
//BeforeBatchSave event
function save(args) {
var addedRows = document.getElementsByClassName("e-insertedrow");
if (addedRows.length) { //checking if new rows are being added
for (var i = 0; i < addedRows.length; i++) {
var checkBoxElement = document.getElementsByClassName("e-insertedrow")[i]
.querySelector(".checkboxstyle"); //accessing checkbox element
var checkboxInstance = $(checkBoxElement).ejCheckBox('instance'); //checkbox instance
var checkboxValue = checkboxInstance.model.checked; //collecting checkbox value
args.batchChanges.added[i].BooleanColumn = checkboxValue;
//setting the checkbox value to the "BooleanColumn" in batchChanges
}
}
}
</script>
|