Overview
jQuery DataTables already has official plug-in for column reordering ColReorder. But if you need the ability to resize columns, you may want to use ColReorderWithResize instead.
Plug-in can be initialized multiple ways:
-
Using dom option and adding character
R
.var table = $('#example').DataTable({ 'dom': 'Rlfrtip' });
-
Using
new $.fn.dataTable.ColReorder()
.var table = $('#example').DataTable(); new $.fn.dataTable.ColReorder(table);
Example
Allow column resizing only
You can disable column reordering and allow column resizing only by setting colReorder.allowReorder
option to false
.
var table = $('#example').DataTable({
'dom': 'Rlfrtip',
'colReorder': {
'allowReorder': false
}
});
Hello, how can i catch the event of column resize. Thanks.
Hi mik, you can catch it like this:
Hi,
I am trying to use this js ColReorderWithResize.js replace dataTables.colReorder.min.js
the resize and reorder worked
however, the column select input filter not working, it worked in dataTables.colReorder.min.js but not this new js
is there a conflict?
Hi,
append select input filter to your example, not working
$(“#example tfoot th”).each( function ( i ) {
var select = $(”)
.appendTo( $(this).empty() )
.on( ‘change’, function () {
table.column(i )
.search( $(this).val() )
.draw();
} );
table.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( ”+d+” )
} );
} );
Hi,
By another testing, to use this js, the stateSave not work
You can try opening an issue on GitHub.
Your code worked fine for me. Try my exact code.
Worked out perfectly!!! Thanks
Also, to fixed a column and disallow it from being re-ordered and resized
Finally the following plugin is need for the datatable fixed column:
https://cdn.datatables.net/fixedcolumns/3.2.6/js/dataTables.fixedColumns.min.js
Is there a way to use this with sort disabled ? I see that this will not work if sort is disabled in datatables!!
Hello, how to use
scrollX
with colReorder? Thanks!Is there a way to disable reordering and only using resize?
Great question! I have updated the article demonstrating how to only allow column resizing. See this example for demonstration.
Thanks for quick help, I am also facing issue when we are having a scrollX and scrollY
See this issue on GitHub, seems like it has been in fixed in the recent update. Try using the most recent version of the plug-in and see if it resolves your problem.
Hi Michael,
The resize fails when we use scrollX and scrollY – it only allows to move the header, not other rows. Can you please suggest?
Please see my earlier reply. This issue on GitHub has been in fixed in the recent update. Try using the most recent version of the plug-in and see if it resolves your problem.
Thank you, Michael – I will check this.
Apologies for another question on this – Is there a way to enable resizing only for a selected set of columns? I would just want to do it for 2 columns.
Is there a way to make it work with RTL table?
I’m using Datatable
for setting the width for each column, but while using this the resizing functionality is not working properly. If I removing the width setting area then it’s working fine. Is there any way to do it without removing the width setting area.
Resizing with ColReorderWithResize plugin works the same for me when using the `columns.width` option, see this example. Also I tried disabling automatic width calculation with `autoWidth: false`.
Yes, sir, I’m also using the same, `autoWidth: false` but the column width is not persisting its actual width. There is some flickering is there.
Cant make column width smaller than content length with white-space:nowrap;
Hi sir,
I have a doubt about the column resize plugin. I will post my code here for your reference. My issue is when im trying to resize the column width by dragging it, it gets retained its previous position when releasing mouse click.
here is my code
I found this is because of ScrollX and ScrollY – can you tell me any solution or suggestion for this. I’m using ScrollX and ScrollY for responsive purposes.
Hi is there any solution for 100+ entries in one page because the table moves very slow while resizing …
The Plugin works fine for me.
But the only issue i’m facing is that, the column widths are not saved after resize. As soon as i click the refresh button, the changes are gone. I want the modified column widths to be saved.
Any help would be appreciated. Thank You.
I am not the original author of the plug-in. It seems that plug-in doesn’t save/restore column widths. Please see [this issue](https://github.com/jeffreydwalter/ColReorderWithResize/issues/13) for insight on how it could be done.
Does it work with Bootstrap 4?
My DOM looks like this:
Where do I insert the “R”?
Letter
R
just need to be present in thedom
option, for example:Hi, I want to do resize only specific columns of table.
I have included the JS file with DataTables 1.10.15 but I get a JavaScript error that oApi not found. How do i get around this error? Fails on this line:
$.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop, invalidateRows )