Hi
I have multiple grids in a page, and I have enabled editing in single click .
That works great but I have 3 additional requirements that I can’t figure out.
1.The cell clicked should be selected, not the first cell in the row.
2. If a checkbox is clicked the checkbox should change from checked to unchecked or from unchecked to checked on first click. Now you must click twice for it to change.
3. I have multiple grids in page. How do I loop through all grids in page and endEdit() in all of them?
Hoppe you understand what I want to do.
Regards,
/Stefan
Index.cshtml
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="273" load="load" actionComplete="actionComplete" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
…
</ejs-grid>
<script>
var isVerifiedColumn = false;
function load(args) {
var instance = document.getElementById('Grid').ej2_instances[0];
instance.element.addEventListener('mousedown', function (e) {
isVerifiedColumn = e.target.getAttribute('aria-colindex') === "0" ? true : false; // Verified column rowIndex = “0”
if (e.target.classList.contains("e-rowcell")) {
if (instance.isEdit)
instance.endEdit();
var index = parseInt(e.target.getAttribute("Index"));
instance.selectRow(index);
instance.startEdit();
};
});
}
function actionComplete(args) {
if (args.requestType == "beginEdit") {
if (isVerifiedColumn) {
if (args.rowData.Verified == false) {
args.form.querySelector('.e-checkbox').ej2_instances[0].checked = true;
}
else {
args.form.querySelector('.e-checkbox').ej2_instances[0].checked = false;
}
}
}
}
</script>
|
Hi,
Thanks for quick answer. This solved 2 and 3.
1. The cell clicked should be selected. The clicked cell should have focus on single click so that you can start editing the cell immediately, see attached image.
Index.cshtml
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="273" load="load" actionComplete="actionComplete" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
…
</ejs-grid>
<script>
var data;
var col;
var focuscell;
var isVerifiedColumn = false;
function load(args) {
var instance = document.getElementById('Grid').ej2_instances[0];
instance.element.addEventListener('mousedown', function (e) {
data = e.target; // details of selected cell element
col = data.getAttribute("aria-colindex"); // respective column of that cell
isVerifiedColumn = e.target.getAttribute('aria-colindex') === "0" ? true : false;
if (e.target.classList.contains("e-rowcell")) {
if (instance.isEdit)
instance.endEdit();
…
};
});
}
function actionComplete(args) {
if (args.requestType == "beginEdit") {
focuscell = args.form.elements[col]; // get the specific cell in the grid form using cell index
setTimeout("foc.focus();", 10); // Set time for focus to enable in the cell
…
}
</script>
|
This works with "ordinary" fields but not with numericedit.
If I have one numericedit column it does not work
in Firefox. Nothing is selected.
If I have two numericedit column it does not work in
Chrome. Click any ship country field and Freight field is selected. Click freight field
and CustomerID field is selected.
Index.cshtml
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" height="273" load="load" actionComplete="actionComplete" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
</ejs-grid>
<script>
function actionComplete(args) {
var grid = document.getElementById("Grid").ej2_instances[0];
if (args.requestType == "beginEdit") {
foc = args.form.querySelector("#Grid" + grid.columns[col].field); // get the field using the column index in a grid instance
setTimeout("foc.focus()", 10);
if (isVerifiedColumn) {
if (args.rowData.Verified == false) {
args.form.querySelector('.e-checkbox').ej2_instances[0].checked = true;
}
else {
args.form.querySelector('.e-checkbox').ej2_instances[0].checked = false;
}
}
</script>
|