I'm developing a web app and am looking for a way to create my own datagrids.
I know that there are lots of fantastic scripts out there with all the bells and whistles, but I need my own specific functionality, css styling, and the ability to use my own ui controls in it.
Really, the only thing I need is the ability to resize the columns. I don't really care if the markup doesn't maintain the row structure or isn't semantic, because all of the data will be populated by ajax requests.
I was thinking a possible solution would be to make each column a div.
Is there a tutorial out there that can help me?
You can resize the columns by just hold click and drag left or right. The table is fully flexible you can drag and slide for resizing, then a horizontal scroll bar will automatically appear.
Make multiple rows or columns the same size Select the columns or rows that you want to make the same size, and then click the Table Layout tab. Under Cell Size, click Distribute Rows or Distribute Columns.
Select the rows or columns and then select Layout and choose your height and width. Select View > Ruler checkbox, select the cell you want, and then drag the markers on the ruler. Note: In Excel, select Home > Format, and then select Column Width.
I recommend to use jQuery UI Resizable with some enhancements. The plugin really focuses only on resizing and enables full customization since you can add your own callback functions at any event. By default, however, the plugin cannot reize table headers, but I could make it running with valid HTML, updating the table's COLGROUP area on resize.
The concrete idea would be:
Plugin init:
$(".resizable th").resizable({
handles: "e",
// set correct COL element and original size
start: function(event, ui) {
var colIndex = ui.helper.index() + 1;
colElement = table.find("colgroup > col:nth-child(" +
colIndex + ")");
// get col width (faster than .width() on IE)
colWidth = parseInt(colElement.get(0).style.width, 10);
originalSize = ui.size.width;
},
// set COL width
resize: function(event, ui) {
var resizeDelta = ui.size.width - originalSize;
var newColWidth = colWidth + resizeDelta;
colElement.width(newColWidth);
// height must be set in order to prevent IE9 to set wrong height
$(this).css("height", "auto");
}
});
I described the full solution including JavaScript, HTML markup, cross-browser CSS and Live-Demo at http://ihofmann.wordpress.com/2012/07/31/resizable-table-columns-with-jquery-ui/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With