Code Monkey home page Code Monkey logo

datatables-rowsgroup's Introduction

datatables-rowsgroup

The Datatables feature plugin that groups rows (merge cells vertically) in according to specified columns. It's inspired by [fnFakeRowspan] (https://datatables.net/plug-ins/api/fnFakeRowspan) DataTables plugin.

Requirements

Requires DataTables v1.10+ and according jQuery version.

Examples

Look at example.html

To use DataTables RowsGroup plugin, include all required js:

<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="http://cdn.datatables.net/1.10.7/js/jquery.dataTables.js"></script>
<script src="dataTables.rowsGroup.js"></script>

and just add array of the columns for 'rowsGroup' DataTable option for which you want enable the rows grouping (order is important):

var table = $('#example').DataTable({
	columns: [
		{
			title: 'First group',
		},
		{
			name: 'second',
			title: 'Second group [order first]',
		},
		{
			title: 'Third group',
		},
		{
			title: 'Forth ungrouped',
		},
		{
			title: 'Fifth ungrouped',
		},
	],
	data: data,
	rowsGroup: [// Always the array (!) of the column-selectors in specified order to which rows groupping is applied
				// (column-selector could be any of specified in https://datatables.net/reference/type/column-selector)
		'second:name',
		0,
		2
	],
})

Also supports manual remerge cells (if you manually deleted showed row, you should execute the method):

var table = $('#example').DataTable({...})
table.rowsgroup.update();

Or you can just set it to be remerged on next redraw (you might stack several times it and then call draw()), and the update() procedure will be called once:

var table = $('#example').DataTable({...})
table.rowsgroup.updateNextDraw();
...
table.rowsgroup.updateNextDraw();
...
while (...) {
	...
	table.rowsgroup.updateNextDraw();
	...
}
table.draw();

License

MIT License

datatables-rowsgroup's People

Contributors

ashl1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

datatables-rowsgroup's Issues

Bower package

This useful plugin needs a dedicated bower plugins. Or not?

Multiples tables, same page, different settings

Hello.

If I have the following code:

    var sset = {
        paging: false,
        searching: false,
        rowsGroup: ['some1:name'],
        columns: [{
            name: 'some1',
            title: 't1',
        }, {
            name: 'some2',
            title: 't2',
        }]
    };

    var uset = {
        paging: false,
        searching: false,
        ordering: false,
        rowsGroup: ['some3:name'],
        columns: [{
            name: 'some3',
            title: 't3',
        }, {
            name: 'some4',
            title: 't4',
        }]
    };

    var table_sorted = $('#table_sorted').DataTable(sset);
    var table_unsorted = $('#table_unsorted').DataTable(uset);

    $("#add_stuff").click(function() {
        for(var i=0; i<4; i++) {
            table_sorted.row.add(['value' + count, i]);
            table_unsorted.row.add(['value' + count, i]);
        }
        table_sorted.draw();
        table_unsorted.draw();
        count++;
    });

Only on of the tables will correctly group rows. The other will not.

In different experiments, the first table is the one which gets rows to group, while in other experiments, it is the second.

Is this a bug in the plug-in, some limitation of it, or am I missing something?

Thank you.

How to use scroller with rowsGroup?

I am loading large amount of data with scroller plugin. How to use scroller plugin with rowsGroup. It works fine on first set of data. As soon as next set of data loads it remove rowsGroup automatically.

Sum column

Im wondering if this library can sum the rowsgroup column?

NAME			ROOM 		BALANCE

Antonio			ROOM1		10
Antonio			ROOM1		5
Antonio			ROOM2		5
John			ROOM1		10

Into this

NAME			ROOM 		BALANCE

Antonio			ROOM1		15
Antonio			ROOM2		5
John			ROOM1		10

Please make amenable to webjars

https://www.webjars.org/

We would very much like to use your package, but we need a fixed release. Can you please add the necessary metadata so that we can build a package via webjars? I think it wants any of the standard (npm, bower, etc) metafiles.

Thank you.

Broken table layout when using child rows

At the beginning: thanks for plugin! I needed it and works well in general.

But I have problem with child rows. When child row is expanded for row with grouped cell, table's layout brokes.

I've created live demo.

It can be handled with more complex code for child rows' displaying/hiding, but maybe there's a possibility to support it in some way on this plugin's level.

Merged Cells content position

Is it possible to have the content of the merged cells at the top of the cell instead of in the middle of it?
Vertical-align set to top in the css sheet doesn't do anything.

EDIT: My apologies. I didn't realize it was an issue from Datatable, not the plugin itself. For those who are wondering about that,

table.dataTable tbody td {
vertical-align: top;
}

Does the trick.

Display "Show 1 to n entries" by grouped row

Hi.

Thanks for very useful feature. I would like to know how can we set datatable to display number of entries by grouped row ? For example:

rowgroup

Total number of entries should be 5 instead of 14.

Thank you and best regards.
Alex

How can i disable auto order rows group

at first before i used the rows group plugin my data in datatables looks like this
image

and after i used the plugin of rows group at my datatables , the data at cells i initialize rows group become auto order to asc like this
image

the function of rows group work fine, but i dont want my data to auto order asc, can you help me solve it to turn off the auto order, or disable it ?

thankyou...

Uncaught TypeError: Assignment to constant variable

I get the following error when I try to assign the rowsGroup setting to column 6.

Uncaught TypeError: Assignment to constant variable

Error traceback to
// Automatic initialisation listener
dataTables.rowsGroup.js:201

$(document).on( 'init.dt', function ( e, settings ) {
	if ( e.namespace !== 'dt' ) {
		return;
	}

	var api = new $.fn.dataTable.Api( settings );

	if ( settings.oInit.rowsGroup ||
		 $.fn.dataTable.defaults.rowsGroup )
	{
		options = settings.oInit.rowsGroup?
			settings.oInit.rowsGroup:
			$.fn.dataTable.defaults.rowsGroup;
		new RowsGroup( api, options );
	}
} );

Global tableOptions

var tableOptions = {
            "columns": [
                {
                    title: "check",
                 
                    "name": "check",
                    orderable: false,
                    className: 'select-checkbox dt-center',
                    targets: [0],
                },
                {
                    title: "status",
                  
                    "name": "status",
                    targets: [1],
                    "visible": true,
                    "className": "dt-center"
                },
                {
                    title: "txtSchoolID",
               
                    "name": "txtSchoolID",
                    "targets": [2],
                    "visible": false,

                },
                {
                    title: "TblPupilManagementAddressesID",
                
                    "name": "TblPupilManagementAddressesID",
                    "targets": [3],
                    "visible": false
                },
                {
                    title: "personID",
                  
                    "name": "personID",
                    "targets": [4],
                    "visible": false
                },
                {
                    title: "pupil_fullname",
                
                    "name": "pupil_fullname",
                    "targets": [5],
                    "visible": true,
                },
                {
                    title: "txtForename" ,
                 
                    "name": "txtForename",
                    "targets": [6],
                    "visible": false
                },
                {
                    title: "txtPreName",
            
                    "name": "txtPreName",
                    "targets": [7],
                    "visible": false
                },
                {
                    title: "txtSurname",
               
                    "name": "txtSurname",
                    "targets": [8],
                    "visible": false
                },
                {
                    title: "parent_full_name",
      
                    "name": "parent_full_name",
                    "targets": [9],
                    "visible": true
                },
                {
                    title: "parent_email",
                    
                    "name": "parent_email",
                    "targets": [10],
                    "visible": true
                },
                {
                    title: "parent_relationship" ,
                   
                    "name": "parent_relationship",
                    "targets": [11],
                    "visible": false
                },
                {
                    title: "initial_mailing_sent",
             
                    "name": "initial_mailing_sent",
                    "targets": [12],
                    "visible": true,
                    "className": "dt-center"
                },
                {
                    title: "reminder_sent",
             
                    "name": "reminder_sent",
                    "targets": [13],
                    "visible": true,
                    "className": "dt-center"
                },
                {
                    title: "letter_salutation" ,
                   
                    "name": "letter_salutation",
                    "targets": [14],
                    "visible": false
                },
                {
                    title: "student_on_trip_uuid",
                   
                    "name": "student_on_trip_uuid",
                    "targets": [15],
                    "visible": false
                },
                {//idea for a preview link to open model iframe?
                    title: "preview",
                   
                    "name": "preview",
                    "targets": [16],
                    "visible": false,
                    "render": function (TblPupilManagementAddressesID, type, full, meta) {
                        return '<a href="" data-toggle="modal" data-target="#exampleModal">Preview</a>';
                    }
                },
                {
                    title: "response",
                   
                    "name": "response",
                    "targets": [17],
                    "visible": true,
                    "className": "dt-center"
                },
                {
                    title: "payment",
                    
                    "name": "payment",
                    "targets": [18],
                    "visible": true,
                    "className": "dt-center"
                },
            ],


            select: {
                style: 'multi',
                selector: 'td:first-child'
            },
            order: [[1, 'asc']],
            paging: false,
            searching: false,
           rowsGroup:[5]
           
        };

My init:

    var table_data = getTableData();
    tableOptions.data = table_data;
    var mailing_table = $('#mailing_table').DataTable(tableOptions);   

Group by several columns together

Is it possible to make a group of several columns?

What I mean is something like

rowsGroup: [0, 
[1,2], //1 and 2 should be "grouped together"
3]

table.draw() -> have ,,DESC" to ,,ASC" or have "ASC" to "DESC" FIXES

[line: 169]
_toogleDirection: function(dir)
{
return dir == 'asc'? 'desc': 'asc';
},

to:

_toogleDirection: function(dir)
{
return dir == 'asc'? 'asc': 'desc';
},

If I have a order: [[0, 'desc']] and I want to call table.draw () then it changes to 'ASC' .
This function _toggleDirection is unnecessary.

incorrect ordering when sorting by non-grouped column

Without the plugin, I am able to set the ordering to ascending, descending or off. But for the columns in the rowGroup array, the ordering can never be in the off state.

It makes some sense that you would code it this way, since dataTables will handle the grouping of the columns for you. With the grouped columns always sorted, equal values will always be grouped together.
But this is not ideal for many use cases.

For instance: If you have a table like this, that lists 1 event per hour.

$('<table>').appendTo('body').DataTable({
    columns: [{title:"Event"},{title: "Hour"}],
    rowsGroup:[0],
    data : [
        ["server started", 1],
        ["flag raised",    2],
        ["flag lowered",   3],
        ["flag raised",    4],
        ["flag lowered",   5],
        ["flag raised",    6],
        ["flag lowered",   7],
        ["server stopped", 8]
    ]
});

When sorting by the "hour" column, I would expect the "server started" group (single row) would be moved to the top, followed by the "flag raised" , then "flag lowered" and finally "server stopped"
The hour column would not be sorted perfectly due to the grouping of rows, but it would show which event happened first by bringing it to the top. But this does not happen because the event column is always sorted first. In a table like this with many event types and hundreds of rows, it would be very difficult to find which event happened first. Even using the shift key, the rows are never sorted correctly.

Expected result when sorting by hour column (note the "event" column is not sorted)

Event           | Hour
-----------------------------
server started	| 1
flag raised     | 2
                | 4
                | 6
flag lowered	| 3
                | 5
                | 7
server stopped  | 8

Real result sorting by hour column

Event           | Hour
-----------------------------
flag raised     | 2
                | 4
                | 6
flag lowered	| 3
                | 5
                | 7
server started	| 1
server stopped  | 8

Maximum call stack exceeded after destroy and reinit

First time when the data is generated with Data parameter the DataTable & rowsGroup loads perfectly. When I make a ajax call to get new Data for the DataTable, I do ".clear()" & ".destroy()" and repopulate the DataTable. But my page Hangs and I face this error "Maximum call stack size exceeded". After 5-10 secs the DataTable loads with the new data and rows group modifications. I have tried with all possbile solutions but getting the same Error.
Hoping for a reply.

Multiple Tables

Hi everybody, I use RowsGroup and I think it should work perfect fine. I got this issue using Multiple Tables, the first table works right. The second one doesnt. and in console throws 'Uncaught RangeError: Maximum call stack size exceeded'.

I dont know what to do anymore. If I fix it, my project will be ok.

Here's my code:

`$(document).ready(function () {

  var table = $('table.tabela').DataTable({


    'columnDefs': [
      {
        'targets': [1, 2, 3, 4, 5],
        'orderable': false,
        'searchable': false
      }
    ],
    'rowsGroup': [0],

    "language": {
      "sEmptyTable": "Nenhum registro encontrado",
      "sInfo": "", //"Mostrando de _START_ até _END_ de _TOTAL_ registros",
      "sInfoEmpty": "", //"Mostrando 0 até 0 de 0 registros",
      "sInfoFiltered": "", //"(Filtrados de _MAX_ registros)",
      "sInfoPostFix": "",
      "sInfoThousands": ".",
      "sLengthMenu": "_MENU_ resultados por página",
      "sLoadingRecords": "Carregando...",
      "sProcessing": "Processando...",
      "sZeroRecords": "Nenhum registro encontrado",
      "sSearch": "Pesquisar",
      "oPaginate": {
        "sNext": "Próximo",
        "sPrevious": "Anterior",
        "sFirst": "Primeiro",
        "sLast": "Último"
      },
      "oAria": {
        "sSortAscending": ": Ordenar colunas de forma ascendente",
        "sSortDescending": ": Ordenar colunas de forma descendente"
      },
      "select": {
        "rows": {
          "0": "Nenhuma linha selecionada",
          "1": "Selecionado 1 linha",
          "_": "Selecionado %d linhas"
        }
      },
      "buttons": {
        "copy": "Copiar para a área de transferência",
        "copyTitle": "Cópia bem sucedida",
        "copySuccess": {
          "1": "Uma linha copiada com sucesso",
          "_": "%d linhas copiadas com sucesso"
        }
      }
    },
    scrollY: false,
    scrollX: true,
    scrollCollapse: true,
    paging: false,
    fixedColumns: true,
    order: [],
    columns: [
      { "orderable": false },
      { "orderable": false },
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      null,
      { "orderable": false },
      { "orderable": false },
    ]
  });

});
`

bug with pagination

hello Alexey Shildyakov. I recently used your Datatables feature plugin that groups rows (merge cells vertically) according to specified columns. It is very nice and useful and I really like it.... However, I found a bug. When I use a dataTable witch has pagenumbers (paging: true), it doesn't work completely. The problem is, it only works for the first page, but when i go to second page, it doesn't work. I created an example and I attached it to this message. You will need to unzip it and open it with any browser.
rowgroup2.zip

Ordering column

Hello, I don't understand how columns ordering work.
When I'm ordering on names, this only order the name inside the group accountant, but not the entirely table.

fiddle

working with inner table

I have a demo that I used with datatables with inner table using ajax.

I have rows. On the first columns of each rows I add a collapse/expand sign. When I click on that link, it do a new ajax call and it will create a inner table (using the same layout at the main table) and this table will be insert after a row group.

The problem is the row containing the inner table dissapears once the rowgroup kick in. and if I put this line in comment in my inner table declaration, it will works : // rowgroup[0,1]

I'll try to make a demo that is not using proprietary code.

Plugin forces the column order to ASC in order to build the groups?

Hi, I am using Datatables 1.10.21 and Datatables RowsGroup v1.0.0 with Server-side rendering.

Columns 0 and 1 are set for rows grouping option inside table object as:

"rowsGroup": [
0,
1
],

If I select Column 0 order I get the correct values for 'order' and 'orderDir' on the server-side. When I Select the Column 1 sort option, the server-side code collects the correct 'order' value (i.e. "1"), but 'order' is always equal to "ASC".

However, I realized that double-click on the column sort option (when "ASC" is active) send order="DESC" on the server-side.

Is there any posibility to make column sorting work as in original datatables without RowsGroup plugin? Thank's in advanced.

Uncaught RangeError: Maximum call stack size exceeded

@ashl1 Hello, I really liked the plugin, i m trying to achieve "RowGroup" past couple of days, havent find anything, I found this, I have copied your min.js and trying to implement in React Project, i m getting this Stack size Error,
Do u have any idea to fix this Issue?

Thanks in Advance!

Fortify vulnerability appears on rowsgroup.js

The call to on( ) in dataTables.rowsGroup.js on line 65 sets a callback that could lead
to a race condition.

var self = this;
---> dt.on('order.dt', function ( e, settings) {
if (!self.orderOverrideNow) {
self.orderOverrideNow = true;
........
}

rowsGroup event "preDraw" not firing on ajax.reload()

On line 73 of your version 1.0.1 you listen for an event called 'preDraw.dt':

dt.on('preDraw.dt', function ( e, settings) {
    if (self.mergeCellsNeeded) {
        self.mergeCellsNeeded = false;
        self._mergeCells();
    }
})

I'm observing that this event does not fire after reloading the ajax source using table.ajax.reload(); - although the table correctly reloads and displays the newdata, rowsGroup fails to merge the same neighboring duplicate cells that it succeeded in merging on the initial page load.

Possibly relevant: my code has its own listener on the table's "draw.dt" event, although it simply runs a function that does not mess with the table itself. Is there a hook in your plugin that I should be using to trigger rowsGrouping to work in my listener function?

error

After destroy previous table and create new table with row grouping getting Maximum call stack size exceeded error .

Error grouping column with input

Hi,

I'm using your plugin on multiple columns in a small datatable. It all works perfectly until I try to group a column with an input in it. I get an error regarding this column - Requested unknown parameter '5' for row 0, column 5

However if I click OK on the error the table is rendered correctly. Is this a known issue? Here is my code:

var table = $("#tblVacancyRates").dataTable({ jQueryUI: true, paging: false, info: false, sort: false, processing: true, "bAutoWidth": false, "bFilter": false, "aaSorting": [], "oLanguage": { "sEmptyTable": "No trades found" }, data: listData, columns: [ { width: "25%", orderable: false, data: 'Trade.Description', name: 'trade' }, { width: "17%", orderable: false, data: 'TradeClassification.Description', name: 'classification' }, { width: "12%", orderable: false, data: 'RateCode' }, { width: "5%", orderable: false, render: function (data, type, row, meta) { var input = row.PayRate; if (row.ReadOnly === false) input = '<input type="text" class="rate" id="txtVacancyPayRate_' + row.ID + '" value="' + row.PayRate + '" />'; return input; } }, { width: "5%", orderable: false, render: function (data, type, row, meta) { var input = row.ChargeRate; if (row.ReadOnly === false) input = '<input type="text" class="rate" id="txtVacancyChargeRate_' + row.ID + '" value="' + row.ChargeRate + '" />'; return input; } }, { width: "3%", orderable: false, name: 'places', render: function (data, type, row, meta) { var input = '<input type="text" style="width:40px;" id="txtPlaces_' + row.TradeID + '" value="' + row.TradeID + '" />'; return input; } }, { width: "19%", orderable: false, data: 'VacancyComments', name: 'comments' }, { width: "6%", orderable: false, data: 'RecruitmentVacancyID', name: 'vacancyID' }, { width: "8%", orderable: false, data: 'VacancyStatus', name: 'status' }, ], rowsGroup: [ 'trade:name', 'classification:name', 'comments:name', 'vacancyID:name', 'status:name', 'places:name' ] });

The output of the input element:

<input id="txtPlaces_69601" style="width: 40px;" type="text" value="69601">

There are 8 rows and the element is identical in each.

If you need more information please let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.