Code Monkey home page Code Monkey logo

colresize's Introduction

colResize 0.0.11 - CURRENTLY IN REVIEW

A DataTables plugin for dynamic resizing of columns

Requires: DataTables 1.10.2 or greater

Installation

To use ColResize, first download DataTables ( http://datatables.net/download ) then download dataTables.colResize.js into an extensions directory in the DataTables package.

Basic usage

ColResize is initialised using the Z option that it adds to DataTables' dom option. For example:

$(document).ready( function () {
	$('#example').dataTable( {
		"dom": 'Zlfrtip'
	} );
} );

ColResize supports both fixed width tables and variable width tables. Fixed width table splits the column width difference between itself and its neighbour column. Variable width tables increase/decreases the width of the table the same amount as the column being resized. In order for a variable width tables to work, the table needs to be wrapped in a container that allows the table to resize. One way is to wrap it in a div that has a style of overflow-x: auto. By default it is fixed width, for variable set tableWidthFixed to false:

$(document).ready( function () {
	$('#example').dataTable( {
		"dom": 'Zlfrtip',
		"colResize": {
			"tableWidthFixed": false
		}
	} );
} );

ColResize has right to left(rtl) support. This changes which neighbouring column is resized. Make sure the table is set to rtl as well otherwise this property will not work. For right to left set rtl to true:

$(document).ready( function () {
	$('#example').dataTable( {
		"dom": 'Zlfrtip',
		"colResize": {
			"rtl": true
		}
	} );
} );

To exclude columns from resizing simply add the index to the exclude array.

$(document).ready( function () {
	$('#example').dataTable( {
		"dom": 'Zlfrtip',
		"colResize": {
			"exclude": [0,1,2]
		}
	} );
} );

You can set a callback function for when the user is done resizing.

$(document).ready(function() {
	$('#example').DataTable( {
		"dom": 'Zlfrtip',
		"colResize": {
			"resizeCallback": function(column) {
				alert("Column Resized");
			}
		}
	} );
} );

You can adjust the width of the resize handle (in px).

$(document).ready(function() {
	$('#example').DataTable( {
		"dom": 'Zlfrtip',
		"colResize": {
			"handleWidth": 10
		}
	} );
} );

colresize's People

Contributors

1jesper1 avatar dykstrad avatar tdillan avatar the86freak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

colresize's Issues

Resizing not working with X scrolling

Hi, I've been trying to get this plugin to work with an X-scrolling datatable, but so far I've been unsuccessful.
I asumed I need to set the "tableWidthFixed": false in the options, but this didn't change much.
I made a quick JSFiddle to show you where I'm at, the resize cursor is appearing, and if you click and drag there is movement, but the columns are not really resizing:
http://jsfiddle.net/kzgq1L25/6/

Thanks for taking a look at this, and thanks for this plugin in general!

have an advice to the longer words in td/th element of datatable.it will do better with colResize feature

If you add the css snippet in the file: \examples\resources\demo.css, you will find a good effect when you resize the column width by draggin it.

table.dataTable{
table-layout:fixed;
width: 100%; /* IE6 need define width */
}

table.dataTable thead th,
table.dataTable tfoot th,
table.dataTable tbody td {
overflow:hidden;
white-space:nowrap;
-o-text-overflow: ellipsis; /* Opera /
text-overflow: ellipsis; /
IE, Safari (WebKit) ,Firefox7 already support text-overflow:ellipsis*/
}

The resize doesn't work.

DataTables 1.10.12

When I point my mouse between headers of two rows, I see it changes to this form <->. I try to drag it, but nothing happens.

I try to use it the following way. Some features commented to eliminate a possibility of conflicts.

    data_table = $(table_name_selector).DataTable({
      searchHighlight: true,
      "iDisplayLength": 10,
      //scrollX: true,
      //scrollCollapse: true,
      //scroller: true,
      deferRender: true,
      "order": [],
      dom: 'Z<lBf<"clearfix">ip<rt>ip>',
      //colReorder: true,
      buttons: [
        'copyFlash',
        {
          extend: 'excel',
          title: 'report',
          text: 'Export',
          extension: '.xlsx'
        }
      ],
      "language": {
        "search": "Search within results"
      }
    });

RTL problem

Hi
Please add and check your example files with following tag and configuration
"colResize": { "rtl": true }
<html dir="rtl">..

colResize not working with ColReorder and ColVis

Hi, I am using Datatables 1.10 and found a reference to this project on DataTables.net. I pulled down the js and have been trying to get it to work but no luck. Are there any known "tricks" that need to be done to permit it to work with ColReorder and ColVis? My table is not autosizing and does not have scrollbars.... I am really holding out hope that colResize will do the trick! Thanks for any assistance you might be able to provide.

resize issue

how to resize column to small, it doesn't get smaller then first on load width. Please reply

Issue with two row header

hi,
I'm using this col resize plugin for my datatable and it has a header with two row. when mouse is on first row it works fine but when click on the second row to resize I got an error in IE
Please help me how to solve this problem?

the plugin could not work in IE8 browser

It reported: "对象不支持此属性或方法 dataTables-colResize-0.0.10.js, 行609 字符21" in chinese
the corresponding english: "the object could not support the property or method dataTables-colResize-0.0.10.js, Row 609 Character 21".

if you run it in IE8 mode of IE10 browser,you will find the root cause: this.s.init.exclude.indexOf
this.s.init.exclude是[] empty array. IE8 has not the "indexOf" method, but firefox,chrome,IE9,IE10 has the method. I used the way below to passby,but it could not still work in IE8 and reported a error from dataTable.js. It seems that sWidthOrig = NaNpx .

Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};

Please help me how to fix it in IE8 mode

Auto truncate text and add ellipsis for a column(resizable as well)

Hi there I m using jquery datatable + colresize, right now everything works well in term of rendering content and resizing column, however what I want to achieve here is that

  1. having max-width limitation on some specific column(coz its content can gets very long)
  2. still be able to resize that column, even the new width is shorter than its content, in that case, truncate text and append ellipsis in the end.

What I tried is modifying the below css, does not seem to work, any thoughts? Thanks!
table.dataTable tbody th, table.dataTable tbody td {
padding: 0.25em 0.5em;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
white-space: nowrap;
}

reset width

How can I reset width of all columns on button clik. I opened your js file and found fn reset and how to use it but it's not working. It's showing error:

TypeError: this._fnConstruct is not a function
this._fnConstruct();

I could not find any solution for this on google. Please help

colResize does not work with ColReorder 1.1 using DataTables 1.10

I am trying to use this plugin alongside colReorder for DataTables but they do not integrate properly. After columns are reordered, resizing the reordered or neighboring columns causes issues. Are you doing any testing in conjunction with colReorder so that both features can be used with a single table?

-- Update --

After some investigation, I found the issue and fixed it:

In the fnMouseDown function, the code is finding the column index using the "column-index" property of the resizeCol and resizeColNeighbour data objects. This property does not get updated when the columns are reordered using the ColReorder plugin, even after saving the state and redrawing the table. These properties contain the old index from before reorder. However, the cellIndex property of the resizeCol and resizeColNeighbour objects do get updated when the columns of the table are reordered.

Changing this code in "_fnMouseDown":

 //Store the indexes of the columns the mouse is down on
var idx = that.dom.resizeCol.data("column-index");
var idxNeighbour = that.dom.resizeColNeighbour.data("column-index");

to this:

var idx = that.dom.resizeCol[0].cellIndex;
var idxNeighbour = that.dom.resizeColNeighbour[0].cellIndex;

Fixes the problem.

It doesn't seem to have any detrimental effects on any other part of the plugin functionality, and it now co-operates with colReorder.

I have forked the repo and will make the changes and make a pull request after doing some more testing.

Not working...

What would prevent resizing to work?
I see the pointer changing but my columns do not resize

Interesting improvement for fix a problem when initialize colResize plugin

If a parent datatable contains other datatables, for example I use drilldown on the parent and contains other datatables, when I apply "dom": 'Zlfrtip' to the parent all the childs get colresize behavior.

Even more, resizing parents columns cause resizing childs datatables columns.

I have been looking into this a lot and I saw that when resizing a column colresize look for all the data-column-index attributes in all the tables with same index number and resize them.

Summarizing:

Colresize plugin does not only apply to the specific table because look for all the data-column-index attributes in all datatables.

What I need is apply "dom": 'Zlfrtip' in parent table and in every child table . But I want not interfere one table others

How can I alter the pluging code or where can I look in the initialization for try to
specify table where the colresize plugin must exercise its domain?

I do not know if I explained my problem well , I think it would be very interesting to promote this plugin with that possibility.

Thanks in advance for your help

Resizing with vertical scrolling enabled produces error in jQuery: "Syntax error, unrecognized expression: :nth-child"

This occurs only when vertical scrolling has been enabled. The error is generated for every mousemove event while resizing a column. This problem also prevents the column edge from following the cursor correctly while resizing and it does not end at the correct position on mouseup.

The error is generated from line 489 from the selector passed to the call to find. When the selector string is built, the code uses the data attribute "column-index" for the number given to nth-child, but that attribute isn't actually present on the column's th element and so the call to parseInt produces NaN, which is what causes jQuery to error out when processing the selector.

on column resize ajax call

As i resize column there is a ajax call going as i have bind datatable with serverside call
I want to stop ajax call on column resize, please guide me a way out.

ColResize fnReset gives an error - is enable/disable resize possible?

Hi there

I want to enable/disable column resizing on a datatable as we have an edit and cancel button to toggle this functionality on and off.

So far I have only been able to do this as follows:

  1. on datatable initialise, exclude columns from resize - this works

       "colResize": {
         "exclude": [0, 1, 2]
       },
    
  2. In our edit button click event, use the api to allow all columns to resize - this works

var table = $('#dataTableSites').DataTable();

new $.fn.dataTable.ColResize(table, {
"exclude": []
});

  1. In our cancel button click event, try to disable the resize again - both these fail

var table = $('#dataTableSites').DataTable();
new $.fn.dataTable.ColResize(table, {
"exclude": [0,1,2]
});

new $.fn.dataTable.ColResize(table).fnReset();

this gives the following error:
Uncaught TypeError: this.s.dt.adjust is not a function
at ColResize.fnReset (dataTables.colResize.js:216)

Can anyone help?

regards
Az

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.