Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82284

Changing rowGroup().dataSrc does not work

$
0
0

Hello:
In a React javascript class I am using "datatables.net-rowgroup-bs4": "^1.1.2". I implemented the Data source change event as demonstrated at:
[https://datatables.net/extensions/rowgroup/examples/initialisation/event.html]

I implemented the code as shown there. I had to set my dataSrc as follows:
const myTable = $('mytable').DataTable({
...
...
rowGroup: {
dataSrc: 'userId', //2nd colum in my table (col 1)
},
...
});

I also implemented a disable rowGroup on a click of a link with this code in a function:
myTable.rowGroup().disable().draw();

Now here is my scenario:
1. Web page with my table renders fine and grouping is correct by "userid".
2. I click my link to disable rowGroup. All of the rows in the table that show the "userid" break disappear.
3. I click on another link to group the table again by "userid". There is no change to the table. No "userid" breaks display..
I figure the reason for this is because I disabled rowGroup in step 2. So in my click function to add back the rowGroup by "userid" I enabled rowGroup() and then set the rowGroup().dataSrc value. Here is my code:

        $('a.group-by').on('click', function (e) {
            e.preventDefault();
            if (!jqMapsTable.rowGroup().enabled()) { // RowGroup is NOT enabled - disabled in step 2...
                jqMapsTable.rowGroup().dataSrc($(this).data('column')); //..set the dataSrce column (contains 1)
                jqMapsTable.rowGroup().enable().draw();  //... and enable rowGroup
            }
        });

When this function completes the result is the row under the table header row that typically shows the first "userid" group instead shows "No group". I then tried to set the dataSrc by using the same string value that I used in the rowGroup parameter in the table definition:

jqMapsTable.rowGroup().dataSrc('userId')
.. This throws this error:
jquery.dataTables.js:5928 Uncaught TypeError: Cannot read property 'aDataSort' of undefined

What I am trying to do is offer the capability for my users to turn on and off the rowGroup-ing. Am I doing this wrong or is there perhaps a bug in the datatables code? Please advise and thank you for your time.


Viewing all articles
Browse latest Browse all 82284

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>