- Home
- Forum
- JavaScript - EJ 2
- Is it possible to have two Checkbox columns on the same grid?
Is it possible to have two Checkbox columns on the same grid?
Hi there,
is it possible to achieve having a grid with two checkbox columns so that the user does not have to place the row into edit mode to tick the checkboxes?
I tried adding them as below and the behavior of the grid when ticking items was strange.
I tried the following definition for the columns:
columns: [
{ field: 'IsSelected', type: "checkbox", width: 50 },
{ field: 'IsSelected2', type: "checkbox", width: 50 },
{ field: 'FullName', headerText: 'FullName' },
],
Also on a different matter (JS + Grid again though) If I define a grid column with "width: 100, minWidth: 100, maxWidth:100"
When the grid initially renders the column width gets set to a default that doesn't respect the minimum and maximum or the specified width as it gets set to a width proportionate to the width of the grid.
I hope that my explanation of the problems is clear.
Cheers James
|
{
field: 'Verified',
displayAsCheckBox: true, // render the checkbox in the Column
editType: 'booleanedit', // render the checkbox to edit a cell
width: 100,
}
|
For example, consider the parent container width or screen width is 1400px. Grid calculates total columns width and compares it with the parent containers width. If the parent container width greater than the total columns width then the remaining parent container width is equally shared to all the Columns like normal html table.
If the Grid’s total columns width exceeds its parent container width then the horizontal scrollbar shown in the Grid.
So, when you increase the window screen size, the parent container’s width equally shared to all the Columns. Since this is the default behavior of html table.
Please let us know if you have any concerns.
Hi Rajapandiyan,
Query #1: If I use the booleanEdit and displayAsCheckBox then the user will have to put the row into edit mode to change the values of the checkboxes. Is there any way that the checkboxes could be ticked\unticked without having to edit and update? (The same as you can do with a single column of type = checkbox)
Query #2: I am setting the desired width of the column "width: 100, minWidth: 100, maxWidth:100" so I would have expected that column to be 100px and for the columns that didn't have a width specified to be the ones that adjusted in width.
Cheers James
|
[index.js]
var grid = new ej.grids.Grid({
dataSource: data,
columns: [
{
field: 'OrderID',
headerText: 'Order ID',
width: 'auto',
minWidth: 100,
isPrimaryKey: true,
textAlign: 'Right',
},
{
field: 'Verified1',
template: '<input class="checkboxfield" type="checkbox">',
width: 150,
},
],
queryCellInfo: queryCellInfo,
});
grid.appendTo('#Grid');
function queryCellInfo(args) {
if (args.column.field == 'Verified1' || args.column.field == 'Verified2') {
var checkbox = new ej.buttons.CheckBox({
checked: args.data[args.column.field],
change: checkboxChange,
});
// Render initialized CheckBox.
checkbox.appendTo(args.cell.querySelector('.checkboxfield'));
}
}
function checkboxChange(args) {
var rowInfo = grid.getRowInfo(args.event.target.closest('td'));
var updatedData = rowInfo.rowData;
updatedData[rowInfo.column.field] = args.checked; // modify the row data
grid.updateRow(rowInfo.rowIndex, updatedData); // updateRow(rowIndex,data)
}
|
Please let us know if you have any concerns.
Hi Rajapandiyan,
both suggestions worked a treat :)
Thank you very very much
- 5 Replies
- 2 Participants
- Marked answer
-
JC James Carter
- Nov 5, 2021 04:53 PM UTC
- Nov 12, 2021 04:17 AM UTC