We are implementing a user preference to (instantly) show \"more\" or \"less\" data on the grid. \"More\" should increase the row-height (with every row having the same incr
Indeed it is possible to dynamically update row height based on user interaction. the Slickgrid API
provides all that we need.
Because:
css
at row & cell level.
Here is a simple demo to get things started:
////////////////////////////////////////////////////////////////////////////////
//example codez re trying to create a grid with rows of dynamic height to
//cater for folks that wanna bung loads of stuff in a field & see it all...
//by violet313@gmail.com ~ visit: www.violet313.org/slickgrids
//have all the fun with it ;) vxx.
////////////////////////////////////////////////////////////////////////////////
modSlickgridSimple=(
function()
{
var _dataView=null;
var _grid=null;
var _data=[];
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
var getPaddingItem=function(parent , offset)
{
var item={};
for (var prop in _data[0]) item[prop]=null;
item.id=parent.id+"."+offset;
//additional hidden padding metadata fields
item._collapsed= true;
item._isPadding= true;
return item;
}
//////////////////////////////////////////////////////////////
//this just builds our expand collapse button
//////////////////////////////////////////////////////////////
var onRenderIDCell=function(row, cell, value, columnDef, item)
{
if (item._isPadding==true); //render nothing
else if (item._collapsed) return "";
else
{
var html=[];
var rowHeight=_grid.getOptions().rowHeight;
//V313HAX:
//putting in an extra closing div after the closing toggle div and ommiting a
//final closing div for the detail ctr div causes the slickgrid renderer to
//insert our detail div as a new column ;) ~since it wraps whatever we provide
//in a generic div column container. so our detail becomes a child directly of
//the row not the cell. nice =) ~no need to apply a css change to the parent
//slick-cell to escape the cell overflow clipping.
//sneaky extra
::-webkit-scrollbar
{
width: 12px;
background-color: #B9BACC;
}
::-webkit-scrollbar-track
{
color: #fff;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
}
::-webkit-scrollbar-thumb
{
color: #96A9BB;
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
}
body
{
font-family: Arial, Helvetica, sans-serif;
background-color: #131313;
position: absolute;
top: 5px;
bottom: 5px;
left: 5px;
right: 5px;
}
#grid-simple
{
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
margin: auto;
font-size: 12px;
background-color: #ECEEE9;
}
.toggle
{
height: 16px;
width: 16px;
display: inline-block;
}
.toggle.expand
{
background: url(https://violet313.github.io/assets/expand.gif) no-repeat center center;
}
.toggle.collapse
{
background: url(https://violet313.github.io/assets/collapse.gif) no-repeat center center;
}
/*--- generic slickgrid padding pollyfill ----------------------*/
.dynamic-cell-detail
{
z-index: 10000;
position: absolute;
background-color: #F4DFFA;
margin: 0;
padding: 0;
width: 100%;
display: table;
}
.dynamic-cell-detail > :first-child
{
display: table-cell;
vertical-align: middle;
text-align: center;
font-size: 12px;
line-height: 13px;
}
Less than 200 lines of codes.
fiddle with it!
Incidentally, this is the kind of approach that the also excellent Datatables provides (almost) natively through it's API. &imo it is the correct pattern; & how i am choosing to implement my own stuff using Slickgrid
. But it involves a slight hack and in any case does *not exactly meet the OP requirements; which i claim is possible.
To do dynamic row-heights per-cell, we employ a similar trick but we must also deal with a few side-effects:~
We must:
The Slickgrid API
provides row-based styling via the Grid.getItemMetadata callback interface. In the next fiddle, on line 107, see the onRenderRow
implementation of this interface:
fiddle with it!
Notice also on lines 148-150, i invoke the Slickgrid
Grid.setCellCssStyles API to add a custom dynamic-cell
css
class that sets the overflow
to visible
in order to style away the per-cell overflow clipping.
If the detail content is static, column resizing is a gimme.
Detail content that responds to a change in column width (flowing text or wotnot) requires some work. Padding rows need to be dynamically added and removed accordingly. See (from line 66) the addPadding
and trimPadding
functions in the next fiddle:
fiddle with it!
There's some work to do here also. we need to ensure that no matter whether we are sorting up or down, the padding remains contiguously underneath the parent. See the comparer
on line 136 in this next fiddle:
fiddle with it!
Pretty much a one-liner: if it's padding, then delegate the comparison to the parent. job done. See the pcFilter
on line 192 in the next fiddle:
fiddle with it!
Yay! that's resizing, sorting & filtering in under 500 lines of fairly legible, liberally commented custom javascripts.. i have in fact seen certain fancy input-range-slider
pollyfills with more lines of code ;)
acu
I have only covered the basics. There is that whole selectable/editable aspect to Slickgrid
,, ~which goes beyond my current requirements (sry).
Also:
There is more to be said about this than can reasonably be squeeezed into a SO
answer -notwithstanding the no-references policyguidelines. Anyone interested in knowing more about all this stuff can go here where i go into a fair bit more detail.
Here's a final fun example. it employs all of the above functionality but as can be seen, i have ditched the expando-rows and there are two dynamic content fields. Also, fyi, this example makes use of MutationObservers in order to generate onPostRender
events as an alternative to the Slickgrid
native
asyncPostRender
column option callback:
fiddle with it!
And there we have it. -some of the way towards a DataView-like Slickgrid extension-mod
; & all without needing to resort to horrid hax on the lovely Slickgrid codes. yippee ;)
OoOok! This post is some years old; and i see now that there are several forks of the currently unmaintained original project. ie: https://github.com/6pac/SlickGrid