Column resizing
Column resizing
First of all - cheers for DataTables - it is fantastic!
Anyway, I don't except for a minute this is a new forum topic but I am having real difficulties trying to get any column resizing plugin to work with DataTables - is anyone succesfully using a column resizing plugin with datatables 1.7 and jQuery 1.4.2, and if they are, what are they using?
Please bear in mind that I'm a jQuery newbie!
Cheers
Buzby
Anyway, I don't except for a minute this is a new forum topic but I am having real difficulties trying to get any column resizing plugin to work with DataTables - is anyone succesfully using a column resizing plugin with datatables 1.7 and jQuery 1.4.2, and if they are, what are they using?
Please bear in mind that I'm a jQuery newbie!
Cheers
Buzby
This discussion has been closed.
Replies
Maybe I don't understand your question , but why are you using a column resizing plugin?
Datatables handles the column resizing automatically. Have you tried creating a table and giving column sizes as part of the column definition?
You will also want to take the time to look through the examples, as Allan has provided many great resource there.
Finally, if you're new to jQuery, datatables will be a bit more complex than many plugins, since it does quite a bit more than most. Don't be intimidated... just start simple, get a table working, then explore the more involved options.
Best of luck,
Patrick
The reason this wasn't working originally is because my table (rendered via the .NET 2.0 GridView control) did not include a COLGROUP section. I had to override the Render method to ensure a COLGROUP section and COL tag was present for each column, then the column resizing worked fine.
I got everything to work, but I am experiencing strangeness when combining this with ColReorder.js plugin. At first, the stable build was breaking at around line 162:
[code]/*
* Move the DOM elements
*/
if ( oSettings.aoColumns[iFrom].bVisible )
{
/* Calculate the current visible index and the point to insert the node before. The insert
* before needs to take into account that there might not be an element to insert before,
* in which case it will be null, and an appendChild should be used
*/
var iVisibleIndex = this.oApi._fnColumnIndexToVisible( oSettings, iFrom );
var iInsertBeforeIndex = null;[/code]
where iFrom was null.
I updated to the latest nightly build and column reordering works. However, when I resize after moving a column, kiketables is resizing the wrong column. Has anyone experienced this and found a workaround?
http://jsfiddle.net/ydTCZ/
The only thing I changed was the
[code] $("table th")[/code]
to
[code] $("table td") [/code]
because I have my filters in the header as TDs. This makes it easier to resize without interfering with the sorting.
Allan
But maybe it can be improved by dragging only the col header extremity ?
Allan
Where can i post my code ?
Allan
Regard.
Christophe
I'm currently investigating column re-sizing with datatables.net
and would be very interested in cbattarels solution as I require column reordering as well.
Is it possible to get a link to the source?
Regards
Allan
Allan
Thank you :)
- both of you
One slightly ugly side effect at the moment is the bar above the table headers and the bar below the table where it shows 'Showing x to x of x entries' loses it's styling as soon as I specify an sDom parameter ""Rlfrtip" as shown as the initialisation in the example. The 'R' is obviously the addition and that is working. After some hacking around I found the stock code where sDom is not specified yields:
[code] 'sDom': '<"H"lfr>t<"F"ip>'[/code]
so I added the 'R' and all is well:
[code]'sDom': 'R<"H"lfr>t<"F"ip>'[/code]
Should the example initialisation code be modified a bit or is there a better way?
Love how just when I need something for DT, I turn around and there it is...!
Allan
Is this in sync with ColReorder?
Reordering columns by dragging a column from anywhere to the right and moving it anywhere to the left seems to break the math for the indices... after reordering, I click on a header to sort, and the data ends up in the wrong columns.
Ironically, although it's the Reorder portion that this is forked from, it's the resize functionality I need more desperately; but the plugin has no options so I can't turn off the reordering while keeping the resizing.
Wish I had a public link to share, but alas I do not.
Allan, Is there a chance to add availability to turn off the reordering functionality of Colreorder, leaving only the resizing?
[UPDATE: found it. https://github.com/DataTables/DataTables]
----------------------
Larger resize handle
In _fnMouseListener, I modified
[code]if (e.pageX == Math.round(offset.left + nLength)) {[/code]
to
[code]
var columnBorderX = Math.round(offset.left + nLength);
if (e.pageX > (columnBorderX - 4) && e.pageX < (columnBorderX + 4)) {
[/code]
This isn't working entirely as the code makes it seem like it should. It only allows a 4px area to "grab" the handle on the left of the column border. The area to the right is negated by the mouselistener on the adjacent TH. This is obviously just a hack, but it is doing the trick for me at the moment.
-------------------------
Stop sorting when resizing
In our implementation, we wrap datatables in our own plugin because almost all the tables on the site use the same basic configuration. So just before the oTable.datatable(config) call, I add the following, a clue I got here: http://www.datatables.net/forums/discussion/1045/click-sort-handler/p1#Comment_5347
[code]
oTable.find('thead th').bind("click.MyDT", function(event){
if ($(event.target).css('cursor') === 'col-resize'){
event.cancelBubble = true;
event.stopImmediatePropagation();
}
});
[/code]
[code]
/*
* Update DataTables' event handlers
*/
/* Sort listener */
for ( i=0, iLen=iCols ; i
edit: the solution only works after you reorder at least one column
edit2: i found it works if I trigger a dummy sort in the constructor. something like this:
[code]
this.s.dt.oInstance.fnColReorder(0,1);
this.s.dt.oInstance.fnColReorder(1,0);
[/code]
edit3: that messes around with the sorting functionality...
http://datatables.net/forums/discussion/7377/disable-all-sorting-after-init/p1
After incorporating that plugin, do something like this in _fnMouseListener:
[code]
/* are we on the col border (if so, resize col) */
var columnBorderX = Math.round(offset.left + nLength);
if (e.pageX > (columnBorderX - 4) && e.pageX < (columnBorderX + 4))
{
that.s.dt.oInstance.fnSortOnOff( '_all', false );
$(nThTarget).css({'cursor': 'col-resize'});
} else {
$(nThTarget).css({'cursor': 'pointer'});
that.s.dt.oInstance.fnSortOnOff( '_all', true );
}
[/code]
There's probably a better way to do this, but seems to work for now.