I am trying to prevent a checkbox column (first column) on a gird from reordering, I overrided the grid-column-reorder event and tried the e.PreventDefault after checking the correct index value(s) with no luck what so ever. I even tried calling grid.reorderColumn with no luck too.
Is there anyway I can prevent a specific column from reordering but allow other columns to reorder ?
12 Answers, 1 is accepted
The Grid does not allow such configuration. The re-size-ing feature could be either activated for all the columns or disabled.
Regards,
Petur Subev
the Telerik team
Do any one have idea how to implement it?
I have also a first checkbox column.
I would like to prevent reordering and resize of the first column that must be a fix column.
Is it possible to obtain this behaviour?
If not, do you plan to add this option? We would like to introduce Kendo Grid in our products, but without this option I don't know if the grid could be used in production..
Thanks.
In the columns definition add a reorderable: false property, and optionally a stickyPosition property (see onReorder).
columns: [
{ field:
"check_row"
, title:
" "
, template:
"<input class='check-row' type='checkbox' />"
, reorderable:
false
, stickyPosition: 0 },
"ProductName"
,
...
]
Set a callback for the columnReorder event.
$(
"#grid"
).kendoGrid({ columnReorder: onReorder, ... });
This onReorder callback function below will place the column back to the stickyPosition column index, or 0 if not provided.
function
onReorder(e) {
if
(
typeof
e.column.reorderable !=
"undefined"
&& !e.column.reorderable) {
var
grid = $(
'#grid'
).data(
'kendoGrid'
);
setTimeout(
function
() {
grid.reorderColumn(e.column.stickyPosition || 0, grid.columns[e.newIndex]);
}, 0);
}
}
function
onReorder(e) {
if
(
typeof
e.column.reorderable !=
"undefined"
&& !e.column.reorderable) {
var
grid = $(
'#grid'
).data(
'kendoGrid'
);
setTimeout(
function
() {
grid.reorderColumn(e.oldIndex, grid.columns[e.newIndex]);
}, 0);
}
}
The solution doesn't work fully. It only keeps you from moving a reorderable column. However, you can move another column that causes the "non-reorderable" column to move.
Assuming your nonreorderable column will be on the end you can use this: (it could be modified to look at columns between the range)
var grid = $(gridName).data('kendoGrid');
if (grid.columns[e.newIndex].reorderable === false || grid.columns[e.oldIndex].reorderable === false) {
setTimeout(function () {
grid.reorderColumn(e.oldIndex, grid.columns[e.newIndex]);
}, 0);
}
Kendo has released a workaround for this.
https://docs.telerik.com/kendo-ui/knowledge-base/grid-prevent-columns-reordering
The previous code suggests that columns have a reorderable property, but it isn't exposed. Can it be?
Hi Peter,
I tested the example in the linked Knowledge Base article and with the latest version 2024.3.806 the example seems to be working as expected (the first column could not be reordered). Please let me know if I am missing something.
I see that you have logged a Feature Rquest for adding a built-in option for the columns to be reorderable and I would like to thank you for that.
I am pasting below a link to the Feature Request in the portal, so the other users in the forum who read this thread could also vote for it:
- https://feedback.telerik.com/kendo-jquery-ui/1667040-singular-column-reorder-functionality
Regards,
Neli
Hi John,
It is correct that the Knowledge base articles are not included in the releases. Indeed, they are additional resources created when there is a demand for specific functionality and are not related to the releases.
I could also see that the Knowledge base has derived from another support ticket and not from the current thread. It also shows a highly simplified version.
If there is anything else I can help with, let me know.
Regards,
Tsvetomir
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
do not misunderstand. I did not have a problem with you doing that. The previous poster said it was in a new release and i was merely saying "no it isn't. It's just on the wiki".
Hi John,
Thank you for taking the time to elaborate on your statement. If there is anything that I can help with, let me know.
Kind regards,
Tsvetomir
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.