Comments (14)
A possible solution would be to temporarily disable the colReorder plugin while the resize is in progress.
You can do this in the available resize start / end hooks. Something like:
var table = $('#example').DataTable({
colResize: {
...
onResizeStart: function() { table.colReorder.enable(false); }
onResizeEnd: function() { table.colReorder.enable(true); }
...
}
});
from datatables.colresize.
Another note,
the ColResize library must be initialized before ColReorder, or else the event listener will call ColReorder first, thus the flag set does not work
from datatables.colresize.
I ran into the same problem,can someone please give me a solution for this?
from datatables.colresize.
Even after disabling column reorder, the column size resets after moving any column.
from datatables.colresize.
@porrey. I just ran in demo above and did not find that to be case. Column size stayed as adjusted after performing column reorder.
from datatables.colresize.
@dhobi. A belated thank you!
from datatables.colresize.
Is state saving on or off?
from datatables.colresize.
On, I believe. You can see the code just by right click / view source.
from datatables.colresize.
The issue occurs when a column width is set in columns[]
or columnDefs[]
during table initialization (width: 100px;
for example). I am initializing the width of my columns.
This video demonstrates the behavoir: https://youtu.be/KOK81An73_0
from datatables.colresize.
ouch. that one will have to be for @dhobi. c
from datatables.colresize.
one thought. you might try setting column widths in style sheet instead of dt.
from datatables.colresize.
@porrey Do you have a minimal example to reproduce the issue?
As the plugin sets the column.width property and the dom (th).outerWidth() I have to see what exactly is going on. Is the table reinitialized on column drag?
from datatables.colresize.
Started working on extracting the example that mimics my actual application (it uses server side processing). I am unable to get the column resizing to work but here is the link. Work in progress...
http://live.datatables.net/porrey/4/edit
from datatables.colresize.
For those facing this problem:
In order to make sure that colResize is registered before colReorder we have to tweak the event logic slightly. Here is the part I added:
// We need to make sure that colResize plugin is registered before colReorder plugin in preInit to be able
// to prevent reorder being triggered when actually resize is expected.
const oEvents = $._data(document, 'events');
const iReorderIndex = oEvents.preInit.findIndex((oEvent) => oEvent.namespace == 'colReorder.dt');
if (iReorderIndex > -1) {
const iResizeIndex = oEvents.preInit.findIndex((oEvent) => oEvent.namespace == 'colResize.dt');
if (iResizeIndex > -1 && iResizeIndex > iReorderIndex) {
const aEvents = oEvents.preInit.splice(iResizeIndex, 1);
oEvents.preInit.splice(iReorderIndex, 0, aEvents[0]);
}
}
It was added after the "preInit" event handler:
With this change I am able to disable "reorder" plugin in "onResizeStart" and enable it again in "onResizeEnd":
colResize: {
isEnabled: true,
saveState: false,
isResizable: (iColumn) => {
return true;
},
onResizeStart: function() { $oTable.colReorder.disable(); },
onResizeEnd: function() { $oTable.table().colReorder.enable(); }
}
Dealing with the event queue of jquery is not the nicest solution but it works. Currently I don't see any other solution as the reorder plugin does not provide any functionality that would help.
from datatables.colresize.
Related Issues (19)
- scroll option with column resize HOT 6
- Header width not matching column width HOT 1
- Upgrading to dataTables.Net 1.12.1 causes resize cursor to not show HOT 1
- .enable(false) can't call internal fnDisable function HOT 2
- CDN links for convenience
- Error occurs when refreshing page if hasBoundCheck = true.
- Cannot read properties of undefined (reading 'fnEnable')
- Third column not working and undefined index HOT 3
- If content text contains underscore character, it's not working HOT 1
- Not working in dataTables v2 HOT 2
- Compatibility issue in DataTable 2.0.0 HOT 2
- Support for RTL languages?
- Width fetched from API is not applied when hasBoundCheck is set to true
- Issue with Chrome - Not working properly HOT 1
- How to save/restore the width via Ajax? HOT 4
- Got error if there are some invisible columns HOT 3
- Got error when resizing columns HOT 1
- Detect the event for resizing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from datatables.colresize.