From 87131856dbc6bfa68e2377d49c548a76c11d2436 Mon Sep 17 00:00:00 2001 From: kantorge Date: Tue, 26 Mar 2024 08:23:26 +0100 Subject: [PATCH] fix: account for various cases of orphaned dividers --- README.md | 2 +- dist/dataTables.contextualActions.min.js | 2 +- docs/index_noheader.html | 495 +++++++++++++++++++++++ docs/sampleData.js | 458 +++++++++++++++++++++ src/dataTables.contextualActions.js | 18 +- 5 files changed, 966 insertions(+), 9 deletions(-) create mode 100644 docs/index_noheader.html create mode 100644 docs/sampleData.js diff --git a/README.md b/README.md index 9b628e5..2c065d0 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,6 @@ $(document).ready(function () { # Development & Building: - Launch the included VSCode workspace file (`datatables-contextual-actions.code-workspace`) - Run `npm i` to install any dependencies -- Perform any development and test in the `~/index.html` file +- Perform any development and test in the `~/index.html` and `~/index_noheader.html` files - When you're ready to build, execute the default build task (`Ctrl + Shift + B`) - Test the built changes in the `~/docs/index.html` documentation/demo file \ No newline at end of file diff --git a/dist/dataTables.contextualActions.min.js b/dist/dataTables.contextualActions.min.js index d2bff44..8ae8f01 100644 --- a/dist/dataTables.contextualActions.min.js +++ b/dist/dataTables.contextualActions.min.js @@ -1 +1 @@ -jQuery.fn.dataTable.Api.register("contextualActions()",function(u){var e=this.table();const h={DIVIDER:"divider",OPTION:"option",STATIC:"static"},b={isDisabled:function(t,e){return t.type!==h.STATIC&&0===e.length||void 0!==t.multi&&!1===t.multi&&1!t.isDisabled(e)).length||"boolean"==typeof t.isDisabledStrictMode&&!0===t.isDisabledStrictMode&&e.some(e=>t.isDisabled(e)))||t.type===h.STATIC&&"function"==typeof t.isDisabled&&t.isDisabled()}};if((u=function e(t,...i){if(!i.length)return t;var n=i.shift();if(s(t)&&s(n))for(const o in n)s(n[o])?(t[o]||Object.assign(t,{[o]:{}}),e(t[o],n[o])):Object.assign(t,{[o]:n[o]});return e(t,...i)}({contextMenu:{enabled:!0,isMulti:!1,xoffset:-10,yoffset:-10,showSpeed:"0.30s",headerRenderer:"",headerIsFollowedByDivider:!1,showStaticOptions:!1,startsNewSelection:!1},buttonList:{enabled:!0,groupClass:"btn-group",iconOnly:!1,disabledOpacity:.5,dividerSpacing:10},classes:[],iconPrefix:"",items:[],deselectAfterAction:!0,showConfirmationMethod:function(e){e.callback(window.confirm(e.message))}},u=null==u?{}:u)).buttonList.enabled&&void 0===u.buttonList.containerSelector)throw"The buttonList.containerSelector option must be specified if the buttonList is enabled, to specify where the buttons will be created";var y={dt:null,table:null,contextMenuId:"",rightClickedRowData:"",init:function(o){this.dt=e,this.table=$(this.dt.container()).find("table"),$(window).click(function(e){$("#"+y.contextMenuId).is(":visible")&&!$(e.target).closest(".dropdown-menu").length&&i()}),this.contextMenuId=(this.table instanceof jQuery?this.table.attr("id"):this.table.id)+"-context-menu",this.rightClickedRowData=[];var s=this;$(this.table).on("contextmenu","tr",function(e){var t=()=>y.table.DataTable().rows().deselect();o.contextMenu.isMulti?s.dt.rows({selected:!0}).indexes().toArray().includes(y.dt.row(this).index())||o.contextMenu.startsNewSelection&&t():t(),s.dt.row(this).select();t=s.table.DataTable().rows({selected:!0}).toArray()[0],t=s.table.DataTable().rows(t).data().toArray();if(o.contextMenu.enabled&&void 0!==t)return i(),s.rightClickedRowData=t,function(t,e){!function(a,e,d,c,l){var r=$(''):(t.type===h.OPTION||u.contextMenu.showStaticOptions&&t.type===h.STATIC)&&(i="",void 0!==t.iconClass&&""!==t.icon&&(i=''),n=void 0!==t.contextMenuClasses?t.contextMenuClasses.join(" "):"",o=void 0!==t.classes?t.classes.join(" "):"",e=void 0!==t.multiTitle&&1'+i+e+""),b.isDisabled(t,l)&&$(s).addClass("disabled").css("opacity","0.5"),1!t.isDisabled(e)):l).length,$(s).append(" ("+e+")")),void 0!==t.confirmation?$(s).click(function(){v(t,l),p(a)}):$(s).click(function(){var e=l.filter(e=>void 0===t.isDisabled||!t.isDisabled(e));p(a),t.action(e,$(s)),u.deselectAfterAction?y.dt.rows().deselect():y.update()}),r.append(s)))}),r.children(":last-child.dropdown-divider").remove(),r.children().each(function(){$(this).hasClass("dropdown-divider")&&$(this).prev().hasClass("dropdown-divider")&&$(this).remove()}),$("body").append(r)}(y.contextMenuId,u.classes,u.iconPrefix,u.items,y.rightClickedRowData);var o=e+u.contextMenu.yoffset,s=t+u.contextMenu.xoffset;if(!1!==u.contextMenu.headerRenderer){t="";try{"string"==typeof u.contextMenu.headerRenderer?t=u.contextMenu.headerRenderer:"function"==typeof u.contextMenu.headerRenderer&&(t=u.contextMenu.headerRenderer(y.rightClickedRowData))}catch(e){t=""}$("#"+y.contextMenuId).find(".dropdown-header").html(t)}setTimeout(function(){$("#"+y.contextMenuId).css({display:"block",visibility:"visible",opacity:0,top:o,left:s,transition:u.contextMenu.showSpeed+" ease all, left 0s, top 0s","z-index":99999}),$("#"+y.contextMenuId).css({opacity:1});var e=$("#"+y.contextMenuId).get(0).getBoundingClientRect(),t=window.innerHeight,i=document.body.clientWidth,n=!1;e.bottom>t&&(o-=e.bottom-t,n=!0),e.right>i&&(s-=e.right-i,n=!0),n&&$("#"+y.contextMenuId).css({top:o-20,left:s-20})},1)}(e.pageX,e.pageY),!1}),this.dt.on("select",function(e,t,i,n){"row"===i&&(i=t.rows({selected:!0}).toArray()[0],i=s.table.DataTable().rows(i).data().toArray(),a(0,o,i))}),this.dt.on("deselect",function(e,t,i,n){"row"===i&&(i=t.rows({selected:!0}).toArray()[0],i=s.table.DataTable().rows(i).data().toArray(),a(0,o,i))}),a(this.dt,o,[])},update:function(){var e=this.dt.rows({selected:!0}).data().toArray();a(this.dt,u,e)}};function i(){$("#"+y.contextMenuId).removeClass("show").hide(),y.rightClickedRowData=[],p(y.contextMenuId)}function a(e,t,i){var n,o,s;t.buttonList.enabled&&(n=t.buttonList,o=t.classes,s=t.items,t=t.iconPrefix,i=i,function(e,t){$.each(t,function(e,t){$(u.containerSelector).removeClass(t)}),$(e).empty()}(n.containerSelector,o),function(d,e,c,l,r){var u='
',p=[],f=null;$.each(c,function(e,t){if(null===f)f=$(u);else{if(0===e&&t.type===h.DIVIDER)return;if(0t.isHidden(e)))||t.type!==h.OPTION&&t.type!==h.STATIC||(s="",o=d.iconOnly?"":"margin-right:10px;",void 0!==t.iconClass&&""!==t.icon&&(s=''),i=void 0!==t.buttonClasses?t.buttonClasses.join(" "):"",n=void 0!==t.classes?t.classes.join(" "):"",e="",o=void 0!==t.multiTitle&&1!t.isDisabled(e)):r).length,d.iconOnly?t.type!==h.STATIC&&1'+e+""),void 0!==t.id&&$(a).attr("id",t.id),(e=b.isDisabled(t,r))?($(a).addClass("disabled"),$(a).attr("disabled","disabled"),$(a).css("cursor","not-allowed"),$(a).css("opacity",d.disabledOpacity),$(a).removeAttr("title","")):!d.iconOnly&&t.type!==h.STATIC&&1void 0===t.isDisabled||!t.isDisabled(e));t.action(e,$(a)),d.deselectAfterAction?y.dt.rows().deselect():y.update()})),f.append(a))}),p.push(f),$.each(e,function(e,t){$(d.containerSelector).addClass(t)}),$.each(p,function(e,t){0void 0===t.isDisabled||!t.isDisabled(e)),e=t.confirmation(n);e.callback=function(e){e&&(t.action(n,i),u.deselectAfterAction?y.dt.rows().deselect():y.update())},u.showConfirmationMethod(e)}function s(e){return e&&"object"==typeof e&&!Array.isArray(e)}return y.init(u),y}); \ No newline at end of file +jQuery.fn.dataTable.Api.register("contextualActions()",function(u){var e=this.table();const h={DIVIDER:"divider",OPTION:"option",STATIC:"static"},b={isDisabled:function(t,e){return t.type!==h.STATIC&&0===e.length||void 0!==t.multi&&!1===t.multi&&1!t.isDisabled(e)).length||"boolean"==typeof t.isDisabledStrictMode&&!0===t.isDisabledStrictMode&&e.some(e=>t.isDisabled(e)))||t.type===h.STATIC&&"function"==typeof t.isDisabled&&t.isDisabled()}};if((u=function e(t,...i){if(!i.length)return t;var n=i.shift();if(s(t)&&s(n))for(const o in n)s(n[o])?(t[o]||Object.assign(t,{[o]:{}}),e(t[o],n[o])):Object.assign(t,{[o]:n[o]});return e(t,...i)}({contextMenu:{enabled:!0,isMulti:!1,xoffset:-10,yoffset:-10,showSpeed:"0.30s",headerRenderer:"",headerIsFollowedByDivider:!1,showStaticOptions:!1,startsNewSelection:!1},buttonList:{enabled:!0,groupClass:"btn-group",iconOnly:!1,disabledOpacity:.5,dividerSpacing:10},classes:[],iconPrefix:"",items:[],deselectAfterAction:!0,showConfirmationMethod:function(e){e.callback(window.confirm(e.message))}},u=null==u?{}:u)).buttonList.enabled&&void 0===u.buttonList.containerSelector)throw"The buttonList.containerSelector option must be specified if the buttonList is enabled, to specify where the buttons will be created";var y={dt:null,table:null,contextMenuId:"",rightClickedRowData:"",init:function(o){this.dt=e,this.table=$(this.dt.container()).find("table"),$(window).click(function(e){$("#"+y.contextMenuId).is(":visible")&&!$(e.target).closest(".dropdown-menu").length&&i()}),this.contextMenuId=(this.table instanceof jQuery?this.table.attr("id"):this.table.id)+"-context-menu",this.rightClickedRowData=[];var s=this;$(this.table).on("contextmenu","tr",function(e){var t=()=>y.table.DataTable().rows().deselect();o.contextMenu.isMulti?s.dt.rows({selected:!0}).indexes().toArray().includes(y.dt.row(this).index())||o.contextMenu.startsNewSelection&&t():t(),s.dt.row(this).select();t=s.table.DataTable().rows({selected:!0}).toArray()[0],t=s.table.DataTable().rows(t).data().toArray();if(o.contextMenu.enabled&&void 0!==t)return i(),s.rightClickedRowData=t,function(t,e){!function(d,e,a,c,l){var r=$(''):(t.type===h.OPTION||u.contextMenu.showStaticOptions&&t.type===h.STATIC)&&(i="",void 0!==t.iconClass&&""!==t.icon&&(i=''),n=void 0!==t.contextMenuClasses?t.contextMenuClasses.join(" "):"",o=void 0!==t.classes?t.classes.join(" "):"",e=void 0!==t.multiTitle&&1'+i+e+""),b.isDisabled(t,l)&&$(s).addClass("disabled").css("opacity","0.5"),1!t.isDisabled(e)):l).length,$(s).append(" ("+e+")")),void 0!==t.confirmation?$(s).click(function(){v(t,l),p(d)}):$(s).click(function(){var e=l.filter(e=>void 0===t.isDisabled||!t.isDisabled(e));p(d),t.action(e,$(s)),u.deselectAfterAction?y.dt.rows().deselect():y.update()}),r.append(s)))}),r.children().each(function(){$(this).hasClass("dropdown-divider")&&$(this).prev().hasClass("dropdown-divider")&&$(this).remove()}),r.children(":last-child.dropdown-divider").remove(),r.children(":first-child.dropdown-divider").remove(),$("body").append(r)}(y.contextMenuId,u.classes,u.iconPrefix,u.items,y.rightClickedRowData);var o=e+u.contextMenu.yoffset,s=t+u.contextMenu.xoffset;if(!1!==u.contextMenu.headerRenderer){t="";try{"string"==typeof u.contextMenu.headerRenderer?t=u.contextMenu.headerRenderer:"function"==typeof u.contextMenu.headerRenderer&&(t=u.contextMenu.headerRenderer(y.rightClickedRowData))}catch(e){t=""}$("#"+y.contextMenuId).find(".dropdown-header").html(t)}setTimeout(function(){$("#"+y.contextMenuId).css({display:"block",visibility:"visible",opacity:0,top:o,left:s,transition:u.contextMenu.showSpeed+" ease all, left 0s, top 0s","z-index":99999}),$("#"+y.contextMenuId).css({opacity:1});var e=$("#"+y.contextMenuId).get(0).getBoundingClientRect(),t=window.innerHeight,i=document.body.clientWidth,n=!1;e.bottom>t&&(o-=e.bottom-t,n=!0),e.right>i&&(s-=e.right-i,n=!0),n&&$("#"+y.contextMenuId).css({top:o-20,left:s-20})},1)}(e.pageX,e.pageY),!1}),this.dt.on("select",function(e,t,i,n){"row"===i&&(i=t.rows({selected:!0}).toArray()[0],i=s.table.DataTable().rows(i).data().toArray(),d(0,o,i))}),this.dt.on("deselect",function(e,t,i,n){"row"===i&&(i=t.rows({selected:!0}).toArray()[0],i=s.table.DataTable().rows(i).data().toArray(),d(0,o,i))}),d(this.dt,o,[])},update:function(){var e=this.dt.rows({selected:!0}).data().toArray();d(this.dt,u,e)}};function i(){$("#"+y.contextMenuId).removeClass("show").hide(),y.rightClickedRowData=[],p(y.contextMenuId)}function d(e,t,i){var n,o,s;t.buttonList.enabled&&(n=t.buttonList,o=t.classes,s=t.items,t=t.iconPrefix,i=i,function(e,t){$.each(t,function(e,t){$(u.containerSelector).removeClass(t)}),$(e).empty()}(n.containerSelector,o),function(a,e,c,l,r){var u='
',p=[],f=null;$.each(c,function(e,t){if(null===f)f=$(u);else{if(0===e&&t.type===h.DIVIDER)return;if(0t.isHidden(e)))||t.type!==h.OPTION&&t.type!==h.STATIC||(s="",o=a.iconOnly?"":"margin-right:10px;",void 0!==t.iconClass&&""!==t.icon&&(s=''),i=void 0!==t.buttonClasses?t.buttonClasses.join(" "):"",n=void 0!==t.classes?t.classes.join(" "):"",e="",o=void 0!==t.multiTitle&&1!t.isDisabled(e)):r).length,a.iconOnly?t.type!==h.STATIC&&1'+e+""),void 0!==t.id&&$(d).attr("id",t.id),(e=b.isDisabled(t,r))?($(d).addClass("disabled"),$(d).attr("disabled","disabled"),$(d).css("cursor","not-allowed"),$(d).css("opacity",a.disabledOpacity),$(d).removeAttr("title","")):!a.iconOnly&&t.type!==h.STATIC&&1void 0===t.isDisabled||!t.isDisabled(e));t.action(e,$(d)),a.deselectAfterAction?y.dt.rows().deselect():y.update()})),f.append(d))}),p.push(f),$.each(e,function(e,t){$(a.containerSelector).addClass(t)}),$.each(p,function(e,t){0void 0===t.isDisabled||!t.isDisabled(e)),e=t.confirmation(n);e.callback=function(e){e&&(t.action(n,i),u.deselectAfterAction?y.dt.rows().deselect():y.update())},u.showConfirmationMethod(e)}function s(e){return e&&"object"==typeof e&&!Array.isArray(e)}return y.init(u),y}); \ No newline at end of file diff --git a/docs/index_noheader.html b/docs/index_noheader.html new file mode 100644 index 0000000..e803264 --- /dev/null +++ b/docs/index_noheader.html @@ -0,0 +1,495 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Datatables-contextual-actions example with no header in popup

+ +
+
+
+ +
+ + diff --git a/docs/sampleData.js b/docs/sampleData.js new file mode 100644 index 0000000..5dc4a96 --- /dev/null +++ b/docs/sampleData.js @@ -0,0 +1,458 @@ +var sampleData = [ + { + fullName: 'Tiger Nixon', + role: 'System Architect', + location: 'Edinburgh', + extension: '5421', + startDate: '2011/04/25', + salary: '$320,800', + }, + { + fullName: 'Garrett Winters', + role: 'Accountant', + location: 'Tokyo', + extension: '8422', + startDate: '2011/07/25', + salary: '$170,750', + }, + { + fullName: 'Ashton Cox', + role: 'Junior Technical Author', + location: 'San Francisco', + extension: '1562', + startDate: '2009/01/12', + salary: '$86,000', + }, + { + fullName: 'Cedric Kelly', + role: 'Senior Javascript Developer', + location: 'Edinburgh', + extension: '6224', + startDate: '2012/03/29', + salary: '$433,060', + }, + { + fullName: 'Airi Satou', + role: 'Accountant', + location: 'Tokyo', + extension: '5407', + startDate: '2008/11/28', + salary: '$162,700', + }, + { + fullName: 'Brielle Williamson', + role: 'Integration Specialist', + location: 'New York', + extension: '4804', + startDate: '2012/12/02', + salary: '$372,000', + }, + { + fullName: 'Herrod Chandler', + role: 'Sales Assistant', + location: 'San Francisco', + extension: '9608', + startDate: '2012/08/06', + salary: '$137,500', + }, + { + fullName: 'Rhona Davidson', + role: 'Integration Specialist', + location: 'Tokyo', + extension: '6200', + startDate: '2010/10/14', + salary: '$327,900', + }, + { + fullName: 'Colleen Hurst', + role: 'Javascript Developer', + location: 'San Francisco', + extension: '2360', + startDate: '2009/09/15', + salary: '$205,500', + }, + { + fullName: 'Sonya Frost', + role: 'Software Engineer', + location: 'Edinburgh', + extension: '1667', + startDate: '2008/12/13', + salary: '$103,600', + }, + { + fullName: 'Jena Gaines', + role: 'Office Manager', + location: 'London', + extension: '3814', + startDate: '2008/12/19', + salary: '$90,560', + }, + { + fullName: 'Quinn Flynn', + role: 'Support Lead', + location: 'Edinburgh', + extension: '9497', + startDate: '2013/03/03', + salary: '$342,000', + }, + { + fullName: 'Charde Marshall', + role: 'Regional Director', + location: 'San Francisco', + extension: '6741', + startDate: '2008/10/16', + salary: '$470,600', + }, + { + fullName: 'Haley Kennedy', + role: 'Senior Marketing Designer', + location: 'London', + extension: '3597', + startDate: '2012/12/18', + salary: '$313,500', + }, + { + fullName: 'Tatyana Fitzpatrick', + role: 'Regional Director', + location: 'London', + extension: '1965', + startDate: '2010/03/17', + salary: '$385,750', + }, + { + fullName: 'Michael Silva', + role: 'Marketing Designer', + location: 'London', + extension: '1581', + startDate: '2012/11/27', + salary: '$198,500', + }, + { + fullName: 'Paul Byrd', + role: 'Chief Financial Officer (CFO)', + location: 'New York', + extension: '3059', + startDate: '2010/06/09', + salary: '$725,000', + }, + { + fullName: 'Gloria Little', + role: 'Systems Administrator', + location: 'New York', + extension: '1721', + startDate: '2009/04/10', + salary: '$237,500', + }, + { + fullName: 'Bradley Greer', + role: 'Software Engineer', + location: 'London', + extension: '2558', + startDate: '2012/10/13', + salary: '$132,000', + }, + { + fullName: 'Dai Rios', + role: 'Personnel Lead', + location: 'Edinburgh', + extension: '2290', + startDate: '2012/09/26', + salary: '$217,500', + }, + { + fullName: 'Jenette Caldwell', + role: 'Development Lead', + location: 'New York', + extension: '1937', + startDate: '2011/09/03', + salary: '$345,000', + }, + { + fullName: 'Yuri Berry', + role: 'Chief Marketing Officer (CMO)', + location: 'New York', + extension: '6154', + startDate: '2009/06/25', + salary: '$675,000', + }, + { + fullName: 'Caesar Vance', + role: 'Pre-Sales Support', + location: 'New York', + extension: '8330', + startDate: '2011/12/12', + salary: '$106,450', + }, + { + fullName: 'Doris Wilder', + role: 'Sales Assistant', + location: 'Sydney', + extension: '3023', + startDate: '2010/09/20', + salary: '$85,600', + }, + { + fullName: 'Angelica Ramos', + role: 'Chief Executive Officer (CEO)', + location: 'London', + extension: '5797', + startDate: '2009/10/09', + salary: '$1,200,000', + }, + { + fullName: 'Gavin Joyce', + role: 'Developer', + location: 'Edinburgh', + extension: '8822', + startDate: '2010/12/22', + salary: '$92,575', + }, + { + fullName: 'Jennifer Chang', + role: 'Regional Director', + location: 'Singapore', + extension: '9239', + startDate: '2010/11/14', + salary: '$357,650', + }, + { + fullName: 'Brenden Wagner', + role: 'Software Engineer', + location: 'San Francisco', + extension: '1314', + startDate: '2011/06/07', + salary: '$206,850', + }, + { + fullName: 'Fiona Green', + role: 'Chief Operating Officer (COO)', + location: 'San Francisco', + extension: '2947', + startDate: '2010/03/11', + salary: '$850,000', + }, + { + fullName: 'Shou Itou', + role: 'Regional Marketing', + location: 'Tokyo', + extension: '8899', + startDate: '2011/08/14', + salary: '$163,000', + }, + { + fullName: 'Michelle House', + role: 'Integration Specialist', + location: 'Sydney', + extension: '2769', + startDate: '2011/06/02', + salary: '$95,400', + }, + { + fullName: 'Suki Burks', + role: 'Developer', + location: 'London', + extension: '6832', + startDate: '2009/10/22', + salary: '$114,500', + }, + { + fullName: 'Prescott Bartlett', + role: 'Technical Author', + location: 'London', + extension: '3606', + startDate: '2011/05/07', + salary: '$145,000', + }, + { + fullName: 'Gavin Cortez', + role: 'Team Leader', + location: 'San Francisco', + extension: '2860', + startDate: '2008/10/26', + salary: '$235,500', + }, + { + fullName: 'Martena Mccray', + role: 'Post-Sales support', + location: 'Edinburgh', + extension: '8240', + startDate: '2011/03/09', + salary: '$324,050', + }, + { + fullName: 'Unity Butler', + role: 'Marketing Designer', + location: 'San Francisco', + extension: '5384', + startDate: '2009/12/09', + salary: '$85,675', + }, + { + fullName: 'Howard Hatfield', + role: 'Office Manager', + location: 'San Francisco', + extension: '7031', + startDate: '2008/12/16', + salary: '$164,500', + }, + { + fullName: 'Hope Fuentes', + role: 'Secretary', + location: 'San Francisco', + extension: '6318', + startDate: '2010/02/12', + salary: '$109,850', + }, + { + fullName: 'Vivian Harrell', + role: 'Financial Controller', + location: 'San Francisco', + extension: '9422', + startDate: '2009/02/14', + salary: '$452,500', + }, + { + fullName: 'Timothy Mooney', + role: 'Office Manager', + location: 'London', + extension: '7580', + startDate: '2008/12/11', + salary: '$136,200', + }, + { + fullName: 'Jackson Bradshaw', + role: 'Director', + location: 'New York', + extension: '1042', + startDate: '2008/09/26', + salary: '$645,750', + }, + { + fullName: 'Olivia Liang', + role: 'Support Engineer', + location: 'Singapore', + extension: '2120', + startDate: '2011/02/03', + salary: '$234,500', + }, + { + fullName: 'Bruno Nash', + role: 'Software Engineer', + location: 'London', + extension: '6222', + startDate: '2011/05/03', + salary: '$163,500', + }, + { + fullName: 'Sakura Yamamoto', + role: 'Support Engineer', + location: 'Tokyo', + extension: '9383', + startDate: '2009/08/19', + salary: '$139,575', + }, + { + fullName: 'Thor Walton', + role: 'Developer', + location: 'New York', + extension: '8327', + startDate: '2013/08/11', + salary: '$98,540', + }, + { + fullName: 'Finn Camacho', + role: 'Support Engineer', + location: 'San Francisco', + extension: '2927', + startDate: '2009/07/07', + salary: '$87,500', + }, + { + fullName: 'Serge Baldwin', + role: 'Data Coordinator', + location: 'Singapore', + extension: '8352', + startDate: '2012/04/09', + salary: '$138,575', + }, + { + fullName: 'Zenaida Frank', + role: 'Software Engineer', + location: 'New York', + extension: '7439', + startDate: '2010/01/04', + salary: '$125,250', + }, + { + fullName: 'Zorita Serrano', + role: 'Software Engineer', + location: 'San Francisco', + extension: '4389', + startDate: '2012/06/01', + salary: '$115,000', + }, + { + fullName: 'Jennifer Acosta', + role: 'Junior Javascript Developer', + location: 'Edinburgh', + extension: '3431', + startDate: '2013/02/01', + salary: '$75,650', + }, + { + fullName: 'Cara Stevens', + role: 'Sales Assistant', + location: 'New York', + extension: '3990', + startDate: '2011/12/06', + salary: '$145,600', + }, + { + fullName: 'Hermione Butler', + role: 'Regional Director', + location: 'London', + extension: '1016', + startDate: '2011/03/21', + salary: '$356,250', + }, + { + fullName: 'Lael Greer', + role: 'Systems Administrator', + location: 'London', + extension: '6733', + startDate: '2009/02/27', + salary: '$103,500', + }, + { + fullName: 'Jonas Alexander', + role: 'Developer', + location: 'San Francisco', + extension: '8196', + startDate: '2010/07/14', + salary: '$86,500', + }, + { + fullName: 'Shad Decker', + role: 'Regional Director', + location: 'Edinburgh', + extension: '6373', + startDate: '2008/11/13', + salary: '$183,000', + }, + { + fullName: 'Michael Bruce', + role: 'Javascript Developer', + location: 'Singapore', + extension: '5384', + startDate: '2011/06/27', + salary: '$183,000', + }, + { + fullName: 'Donna Snider', + role: 'Customer Support', + location: 'New York', + extension: '4226', + startDate: '2011/01/25', + salary: '$112,000', + }, +]; \ No newline at end of file diff --git a/src/dataTables.contextualActions.js b/src/dataTables.contextualActions.js index 83c8122..64cf40f 100644 --- a/src/dataTables.contextualActions.js +++ b/src/dataTables.contextualActions.js @@ -145,7 +145,7 @@ jQuery.fn.dataTable.Api.register('contextualActions()', function (options) { } else{ // The context menu is multi-enabled - + // If the user has right-clicked on a non-selected row var isRowSelected = me.dt.rows({selected: true}) .indexes() @@ -269,7 +269,7 @@ jQuery.fn.dataTable.Api.register('contextualActions()', function (options) { var contextMenuTopPosition = y + options.contextMenu.yoffset; var contextMenuLeftPosition = x + options.contextMenu.xoffset; - + // Generate the header for the menu if (options.contextMenu.headerRenderer !== false) { var headerContent = ''; @@ -304,7 +304,7 @@ jQuery.fn.dataTable.Api.register('contextualActions()', function (options) { 'z-index': 99999, }); - + // After it's been fully rendered, check if it's going off screen $('#' + _ca.contextMenuId).css({ opacity: 1, @@ -500,10 +500,8 @@ jQuery.fn.dataTable.Api.register('contextualActions()', function (options) { } }); - // Finally, since a non-last divider can have a "hidden" item after it that might make it still render last, remove any first/last dividers - menu.children(':last-child.dropdown-divider').remove(); - - // And since a hidden item sandwiched between two dividers can render as 2 dividers back to back, remove duplicate elements + // A hidden item sandwiched between two dividers can render as 2 dividers back to back, remove duplicate elements + // This will account for duplicate dividers at the start or end of the menu menu.children().each(function () { if ( $(this).hasClass('dropdown-divider') && @@ -513,6 +511,12 @@ jQuery.fn.dataTable.Api.register('contextualActions()', function (options) { } }); + // Finally, since a non-last divider can have "hidden" item after it that might make it still render last, remove any last dividers + menu.children(':last-child.dropdown-divider').remove(); + + // Similarly, we remove a divider that became the first item, when the header is not present + menu.children(':first-child.dropdown-divider').remove(); + // Add the menu to the DOM $('body').append(menu); }