Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Column resizing #6

Open
wyuenho opened this issue Nov 26, 2012 · 36 comments
Open

Column resizing #6

wyuenho opened this issue Nov 26, 2012 · 36 comments
Milestone

Comments

@wyuenho
Copy link
Contributor

wyuenho commented Nov 26, 2012

No description provided.

@monzou
Copy link

monzou commented Mar 13, 2013

+1

@wyuenho
Copy link
Contributor Author

wyuenho commented Apr 7, 2013

jQuery handsontable Seem to be able to do this quite semantically with colgroup and a nest div as a column resizer. Would you like to look into this @dandavison ?

@kriswill
Copy link

I was able to use DragTable, a jQuery plug-in that progressively enhances a table to support interactive mouse column reordering. I stored the column order in browser / localStorage and recalled it when configuring Backgrid. I made some changes to the plug-in that allowed for mouse click-thrus, so the header cell would receive sort clicks and contributed those changes back to the upstream project.

The way the plug-in works is by overlaying the original table with a [UL] and re-rendering the columns (for a specified number of rows) then attaching jQuery-UI sortable to it.

This approach probably wouldn't work for a dual-table where the header row is lined up with the body in separate tables, to enable a fixed header. But the visual effect of seeing the column contents while dragging is compelling.

@tailless
Copy link

I used colResizable to make the columns resizable. Trivial to integrate - works fine with backgrid : )

@fizerkhan
Copy link

+1

@lifedispenser
Copy link

@tailless is right. Add colResizeable to the grid after it is initialized, and you are all set. It is being neglected by the author, so make sure you use a forked version of it that has minor bug fixes or converts it to coffeescript.

You can even monkey patch it to accept an array of column width percentages for the initial column sizes.

@mparisi76
Copy link

Can you explain what you mean by "Add colResizeable to the grid after it is initialized"? Perhaps show a code snippet? Thanks!

@kriswill
Copy link

He probably means until it's in the DOM. I've found many jQuery plugins won't work unless the target element(s) are in the DOM. For instance Chosen has this problem and doesn't work very comfortably with Backbone. You should be able to render a Backbone view without appending it to the DOM.

@lifedispenser
Copy link

Yes, that is right. Append it to the DOM first before applying the plugin.

@mparisi76
Copy link

Thanks guys, I just didn't realize that colResizable was a jquery plugin. Everything works great now!

@rapidrapids
Copy link

+1

12 similar comments
@excentris
Copy link

+1

@oosterholt
Copy link

+1

@WRidder
Copy link

WRidder commented Oct 17, 2013

+1

@Wietjerr
Copy link

+1

@ericbeijer
Copy link

+1

@KramerCJ
Copy link

+1

@jurgenkalverboer
Copy link

+1

@beatle01
Copy link

+1

@uuilee
Copy link

uuilee commented Dec 17, 2013

+1

@DavidWinterbottom
Copy link

+1

@mfisscher
Copy link

+1

@PaRoxUs
Copy link

PaRoxUs commented Mar 5, 2014

+1

@jmtoball
Copy link

Any news on this one?

@wyuenho
Copy link
Contributor Author

wyuenho commented May 23, 2014

Not yet. I've been a bit busy and my current contracts aren't paying me to work on it.

Sent from my iPhone

On 23 May, 2014, at 6:26 pm, Johannes Maximilian Toball [email protected] wrote:

Any news on this one?


Reply to this email directly or view it on GitHub.

@wyuenho
Copy link
Contributor Author

wyuenho commented May 23, 2014

@WRidder is working it I think.

Sent from my iPhone

On 23 May, 2014, at 6:26 pm, Johannes Maximilian Toball [email protected] wrote:

Any news on this one?


Reply to this email directly or view it on GitHub.

@WRidder
Copy link

WRidder commented May 28, 2014

That's correct, will give an update as soon as I have an initial version/proposal.

@WRidder
Copy link

WRidder commented Jun 8, 2014

I have created two seperate extensions to adress both (re)sizeable columns and (re)orderable columns. See:

These are proposals which I'd like to discuss with anyone interested. These proposals do not yet contain full documentation and tests.

The overall intent is to make them fit with backgrid in a manner which requires only minor changes to core backgrid and can easily be enabled/disabled.

Sizeable columns

Architecture

It creates an colgroup element as a child of the backgrid table and is to be placed before the thead element. This element contains a col element for every column on which a css width can be set. The advantage of this approach is that a width that is set on a col element is applied to all related cells. Another advantage is that this makes this plugin an easy drop-in.

Currently I've chosen to support a width, max width and a minimum width. These properties can currently be set in the column definition. It sets a data-column-id attribute on every col element to indicate to which column model it belongs.

Usage

// Add sizeable columns
var sizeAbleCol = new Backgrid.Extension.sizeAbleColumns({
  collection: pageableTerritories,
  columns: columns
});
$backgridContainer.find('thead').before(sizeAbleCol.render().el);

Discussion

  • Anyone an objection to using the colgroup element method to control the widths?
  • Is the standard column definition the right place for widths attributes?
  • Are there possibly browsers which do not support this method.

Resizeable columns

Architecture

On rendering it will try to find all relevant header th elements. This also keeps in mind the possibility of having grouped headers. Once all header elements have been determined, it will create handler elements for columns which are both resizeable and renderable. The handlers have been made draggable using standard mouse events. I've chosen not to use third-party libraries like jquer ui draggable to limit dependencies.

It has a dependency on sizeable columns because it needs to interact with the colgroup element created by that extension.

Currently I've chosen to support a width, max width and a minimum width. These properties can currently be set in the column definition.

Usage

// Add sizeable columns
var sizeAbleCol = new Backgrid.Extension.sizeAbleColumns({
  collection: pageableTerritories,
  columns: columns
});
$backgridContainer.find('thead').before(sizeAbleCol.render().el);

// Add resize handlers
var sizeHandler = new Backgrid.Extension.sizeAbleColumnsHandlers({
  sizeAbleColumns: sizeAbleCol,
  grid: pageableGrid,
  saveModelWidth: true
});
$backgridContainer.find('thead').before(sizeHandler.render().el);

// Listen to resize events
columns.on('resize', function(columnModel, newWidth, oldWidth) {
  console.log('Resize event on column; name, model, new and old width: ', columnModel.get("name"), columnModel, newWidth, oldWidth);
});

Discussion

  • Is this a reasonable approach to make elements draggable?
  • Do we need to incorporate touch support?

Reorderable columns

Architecture

On rendering it will try to find all relevant header th elements. This also keeps in mind the possibility of having grouped headers. Once all header elements have been determined, it will create indicator elements for columns which are both resizeable and reorderable. The column header elements have been made draggable using standard mouse events. I've chosen not to use third-party libraries like jquer ui draggable to limit dependencies. On drag a same-size copy of the column's th element is created which can be styled however you want.

As an optimization it does not force the grid to re-render when the order has been changed; it will find all relevant cells and reorder them.

It has a dependency on sizeable columns because it needs to interact with the colgroup element created by that extension.

Usage

// Make columns reorderable
var orderHandler = new Backgrid.Extension.OrderableColumns({
  grid: pageableGrid,
  sizeAbleColumns: sizeAbleCol
});
$backgridContainer.find('thead').before(orderHandler.render().el);

I'd love to hear anyone's input on these extensions.

@WRidder
Copy link

WRidder commented Jun 11, 2014

A small update:

  • IE(8) now supported
  • Grouped columns can now be re-ordered as well

Demo: http://techwuppet.com/backgrid_poc_demo/
Repo resizeable columns: https://github.com/WRidder/backgrid-sizeable-columns/
Repo reorderable columns: https://github.com/WRidder/backgrid-orderable-columns/

@Ratikant01
Copy link

I tried to use sizeable-columns & grouped-columns and I ended up with below error! Any idea where I am doing wrong?

Uncaught RangeError: cannot determine header elements for every column. backgrid-sizeable-columns.js:263

-> I had 0 items first time, and I am showing {No Data} message in td with colspan same as total number of columns!

Thanks

@Ratikant01
Copy link

It seems working now.. Thanks a lot!

@WRidder
Copy link

WRidder commented Jun 26, 2014

Alrighty, can you elaborate on the situation which caused the error and how you fixed it? Also keep in mind that these extensions are still a work in progress. If you would like to participate in the discussion regarding this functionality, see: #501

@excentris
Copy link

The extensions created by @WRidder are currently being maintained here.

@excentris
Copy link

@wyuenho Can you comment on the progress described by @WRidder ?
Thanks!

@lmeyerov
Copy link

@excentris @wyuenho will this get merged in?

@excentris
Copy link

@lmeyerov Unfortunately, I do not see this happening any time soon...
@wyuenho Any word?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests