I would like to provide variable row height depending upon the content size. is it possible in Slickgrid?
Can you point me towards any examples?
I would like to provide variable row height depending upon the content size. is it possible in Slickgrid?
Can you point me towards any examples?
This is possible but it s not trivial and you will likely take a performance penalty. The way SlickGrid works, it needs to be able to answer the following two questions rapidly:
When you use a static row height, answering these questions is trivial; however, with dynamic row height, you ll need to maintain a couple of extra data structures.
Here s roughly what I changed in Slick.Grid.js
To make this practical (performant), you ll also need a cache of row top offsets (a cache of sums of row size). This will enable quick computation for the first question and will allow for binary search to answer the second.
I hope that helps.
I have implemented this in my project, with the help of @Stephen Robinson s answer here.
If anyone is interested they can check:
https://github.com/vihari/Seaview/blob/version3.0/SlickGrid-master/slick.grid.js.
It can be enabled with the file above if you set options.enableWrap to true.
Thank you.
I know this doesn t meet the heart of the question, but decided upon a simple solution for now that is minimal effort and meets my requirements at the moment. So, this is just in case others were looking for a simple solution as well.
I started with an input box, where changing the value would resize the row. However, I ve now settled on using a slider. As a matter of fact, since I have such little data in my grid (guaranteed to be small amounts of data, and very few rows), I dynamically resize the grid as the slider slides. Now, I know many will say this is a terrible idea because it can be horribly slow, but again, I m using a very small amount of data.
The key is that I recreate the grid again with the new rowHeight value set in the options.
Add the code to handle the slider and recreating the grid (alternatively, you could move what I have in the "slide" function to the "stop" function if you don t want to redraw on every sliding tick):
$j( "#resizeRowSlider" ).slider({
range:"min"
, min: 50
, max: 200
, value: 50
, create: function( even, ui ) {
$j("rowResizeValue").html( "50" );
}
, slide: function( event, ui ) {
$j( "rowResizeValue" ).html( ui.value );
options.rowHeight = ui.value;
// I do a manual resize; you could use autoHeight:true in grid options
resizeGrid();
grid = new Slick.Grid("#" + gridElemId, json, columns , options);
grid.setSelectionModel(new Slick.RowSelectionModel() );
refreshGrid(); // Handle invalidate, resizeCanvas
}
, stop: function( event, ui ) {
}
});
Also, I should note that this is not on a per row basis, but again, it fits my needs for now. It s not ideal, but it works. Additionally, if you really need to render the grid the first time without any overflow, you can create a hidden div whenever you get the text in question and add display:table-cell
, then get the div height and set that value the grid options for rowHeight. Then, create (or recreate) the grid.
Plain and simple, this is not supported in SlickGrid and likely will never be. Sorry.
There is also the variable height implementation by JLynch7 on github:
https://github.com/JLynch7/SlickGrid/tree/variableRowHeight
As far as I understand the height is set by user and not automatically computed based on content of the row s cells (I only looked at the example/example-variable-row-height-dataview.html)
I ve recently forked SlickGrid to add in a bunch of new features - including variable (and resizable) rows. You can try it here: https://github.com/globexdesigns/doby-grid
As a summary of the above options none of them are official, supported and production ready. Even the doby-grid option (more supported) is still listed as not production ready.
Note, there are also differences between:
Surprisingly, with all of the SlickGrid variants above (and many other DataGrid libraries), you might get one or two of the above, but not all three.
If you are not so concerned about official, supported and production ready, then this is my impressions from testing the 3 SlickGrid variants listed above:
Seaview
JLynch7
doby-grid
To Vihari Piratla s solution - I ve downloaded Seaview, modified its /SlickGrid-master/examples/example1-simple.html to add the new option enableWrap - during my test the example1-simple.html continue to work as expected when enableWrap is set to false, but when its set to true the grid is drawn empty with no content. I was wondering if there are special way use the enableWrap option?
Define this variable outside....
var tableHeight = 0;
Before creating the slick grid, use below the lines:
// 30 px for each line this will cover the header... You can adjust this value for your table.
tableHeight = dataTable.length * 30;
if(tableHeight > ($(window).height() - 400)){
$("#myGrid").height($(window).height() - 400);
}else{
$("#myGrid").height(tableHeight);
}
If user changes the screen when page is already generated, the below will resize the table based on screen and number of rows of data:
$(window).resize(function() {
// For grid height
if(tableHeight > ($(window).height() - 400)){
$("#myGrid").height($(window).height() - 400);
}else{
$("#myGrid").height(tableHeight);
}
// For grid width
$("#myGrid").width("100%");
// Resize the grid dynamically.
gridName.resizeCanvas();
});
As non of the forks of SlickGrid are really viable options in many regards, I thought it would be valuable to many readers of this post to discuss alternatives to SlickGrid.
I consider viable alternatives that fully support variable row height to be: each row can have a different row height that automatically adapts to fit the content, and lets the text wrap to the next line.
I have looked into this quite extensively, and unfortunately I have not found viable alternatives that are related to SlickGrid. Of other alternatives, I have only found one that is free for commercial use - dojox DataGrid, however it is not clear how you could use custom editors with this (most commercial ones offer this).
There are quite a few viable alternatives that require payment for commercial use: dhtmlxGrid, jQuery EasyUI DataGrid, jQWidgets, Wijmo Grid widget, JideTable, and Sencha ExtJS Grids. Of these, I would personally say the best is dhtmlxGrid http://dhtmlx.com/docs/products/dhtmlxGrid/ - Free version is GPL, Pro version is $199.
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.