Disabling RowGroup when all the data has the same group
Disabling RowGroup when all the data has the same group
For some of my tables I like to disable the rowGroup feature if all the data falls under the same group.
For example, I might have a page that only shows the employees at the office in London, so it doesn't add anything to show "London" in it's own row and then have every employee listed under it.
Here's how I do it:
.on("init", function() {
var groups = table.column("[insert column name here]:name").data().unique();
(groups.length == 1 ? table.rowGroup().disable().draw() : table.rowGroup().enable().draw());
})
This can also be easily modified to disable rowGroup if all the data is unique as well, such as when grouping on employee names, by checking the groups.length
against the number of total records.
@allan, 1) I'm biased :-), but I think this would make a good example under the RowGroup extension examples on how to use the API, and 2) there is not RowGroup option in the "Ask a Question" or "New Discussion" Category dropdown.
Replies
Thanks for posting this!
1) Good suggestion - thanks!
2) Oops - will fix that right now.
Allan
Hmmm - actually no I won't. There seems to be a bug in the forum software stopping me from adding it. its due for an upgrade so I'll get it done then.
Allan
This has quit working for me a while back and I'm just now getting around to asking about it.
Again, I want to disable rowGroup if there is only one group.
Here's the code (table is named "conference_standings_C_038"):
The problem seems to be in the
"sub_conference:name"
portion since when I swap it out with an integer likevar groups = conference_standings_C_038.column(4).data().unique();
it works.
Has something changed with the ability to use a column name?
I think you are not using the correct selector. It should be this:
.on("init.dt", function() {
Selecting the column use
:name
should still work.Kevin
Thanks, Kevin. Unfortunately that's not it. I've changed it ti
init.dt
, but still no luck.Also, the
init
executes as is, but using the:name
doesn't work although using an integer will.Are you using
columns.name
?Using
:name
seems to work in this example:http://live.datatables.net/famafejo/1/edit
Kevin
I'm using
column('[insert column name here]:name')
(no "s"), which I think should work.I've slightly modified your example code (I like your rowGroup disable upfront) and it still works:
http://live.datatables.net/hetupufe/3/edit
Here's where I'm trying to use it on my webpage, which looks practically identical to the example with the exception of the table name and the column name:
https://cfbha.org/w/Special:SeasonHome?view=conferences&season=2018&org=NCAA&div=FBS
However I get a
conference_standings_C_205.column(...).data(...) is undefined
where theconference_standings_C_205
is the table name.All conferences should have two divisions (referred to as "sub_conference" in the data) except the Big Twelve and the Sun Belt. I'd like the ones with the divisions to show the division name in the row group header while have the row group disabled for the other two.
I looked at the source code and found what I think is the Datatable (onference_standings_C_205) you reference. I might be missing it but I don't see a column defined for
sub_conference
. I removed all of the config options exceptcolumns
androwGroup
. I also removed some of the config for the columns themselves. Here is what I see:I might be looking at the wrong Datatable.
Kevin
@kthorngren
Thanks, Kevin . . . I'm thoroughly embarrassed!
I have a PHP object that spits out the Datatables code and I must have removed "sub_conference" from the columns without realizing it.
I've spent all my time troubleshooting the init function and even trying to figure out if the rowGroup extension had changed and I didn't even think to double check the columns.
Sometimes a fresh set of eyes does wonders!
Happens to me all the time
Kevin