Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UMD, package.json, and proper deinitialization #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions dataTables.rowsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,37 @@
*
*/

(function($){
(function( factory ) {
"use strict";

if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['jquery'], function ( $ ) {
return factory( $, window, document );
} );
}
else if ( typeof exports === 'object' ) {
// CommonJS
module.exports = function (root, $) {
if ( ! root ) {
root = window;
}

if ( ! $ ) {
$ = typeof window !== 'undefined' ?
require('jquery') :
require('jquery')( root );
}

return factory( $, root, root.document );
};
}
else {
// Browser
factory( jQuery, window, document );
}
}
(function($, window, document){

ShowedDataSelectorModifier = {
order: 'current',
Expand All @@ -62,7 +92,7 @@ var RowsGroup = function ( dt, columnsForGrouping )
this.order = []

var self = this;
dt.on('order.dt', function ( e, settings) {
dt.on('order.dt.rowsGroup', function ( e, settings) {
if (!self.orderOverrideNow) {
self.orderOverrideNow = true;
self._updateOrderAndDraw()
Expand All @@ -71,35 +101,39 @@ var RowsGroup = function ( dt, columnsForGrouping )
}
})

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

dt.on('column-visibility.dt', function ( e, settings) {
dt.on('column-visibility.dt.rowsGroup', function ( e, settings) {
self.mergeCellsNeeded = true;
})

dt.on('search.dt', function ( e, settings) {
dt.on('search.dt.rowsGroup', function ( e, settings) {
// This might to increase the time to redraw while searching on tables
// with huge shown columns
self.mergeCellsNeeded = true;
})

dt.on('page.dt', function ( e, settings) {
dt.on('page.dt.rowsGroup', function ( e, settings) {
self.mergeCellsNeeded = true;
})

dt.on('length.dt', function ( e, settings) {
dt.on('length.dt.rowsGroup', function ( e, settings) {
self.mergeCellsNeeded = true;
})

dt.on('xhr.dt', function ( e, settings) {
dt.on('xhr.dt.rowsGroup', function ( e, settings) {
self.mergeCellsNeeded = true;
})

dt.on('destroy.dt.rowsGroup', function ( e ) {
dt.off('.rowsGroup');
})

this._updateOrderAndDraw();

/* Events sequence while Add row (also through Editor)
Expand Down Expand Up @@ -241,7 +275,7 @@ $.fn.dataTable.RowsGroup = RowsGroup;
$.fn.DataTable.RowsGroup = RowsGroup;

// Automatic initialisation listener
$(document).on( 'init.dt', function ( e, settings ) {
$(document).on( 'init.dt.rowsGroup', function ( e, settings ) {
if ( e.namespace !== 'dt' ) {
return;
}
Expand All @@ -266,7 +300,7 @@ $(document).on( 'init.dt', function ( e, settings ) {
}
} );

}(jQuery));
}));

/*

Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "datatables-rowsgroup",
"version": "1.0.0",
"description": "The Datatables feature plugin that groups rows (merge cells vertically) in according to specified columns",
"main": "dataTables.rowsGroup.js",
"repository": "[email protected]:futpib/datatables-rowsgroup.git",
"license": "MIT",
"dependencies": {
"jquery": ">=1.7"
}
}