選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

dataTables.searchPanes.js 143KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940
  1. /*! SearchPanes 1.3.0
  2. * 2019-2020 SpryMedia Ltd - datatables.net/license
  3. */
  4. (function () {
  5. 'use strict';
  6. var $;
  7. var dataTable;
  8. function setJQuery(jq) {
  9. $ = jq;
  10. dataTable = jq.fn.dataTable;
  11. }
  12. var SearchPane = /** @class */ (function () {
  13. /**
  14. * Creates the panes, sets up the search function
  15. *
  16. * @param paneSettings The settings for the searchPanes
  17. * @param opts The options for the default features
  18. * @param idx the index of the column for this pane
  19. * @returns {object} the pane that has been created, including the table and the index of the pane
  20. */
  21. function SearchPane(paneSettings, opts, idx, layout, panesContainer, panes) {
  22. var _this = this;
  23. if (panes === void 0) { panes = null; }
  24. // Check that the required version of DataTables is included
  25. if (!dataTable || !dataTable.versionCheck || !dataTable.versionCheck('1.10.0')) {
  26. throw new Error('SearchPane requires DataTables 1.10 or newer');
  27. }
  28. // Check that Select is included
  29. if (!dataTable.select) {
  30. throw new Error('SearchPane requires Select');
  31. }
  32. var table = new dataTable.Api(paneSettings);
  33. this.classes = $.extend(true, {}, SearchPane.classes);
  34. // Get options from user
  35. this.c = $.extend(true, {}, SearchPane.defaults, opts);
  36. if (opts !== undefined && opts.hideCount !== undefined && opts.viewCount === undefined) {
  37. this.c.viewCount = !this.c.hideCount;
  38. }
  39. this.customPaneSettings = panes;
  40. this.s = {
  41. cascadeRegen: false,
  42. clearing: false,
  43. colOpts: [],
  44. deselect: false,
  45. displayed: false,
  46. dt: table,
  47. dtPane: undefined,
  48. filteringActive: false,
  49. forceViewTotal: false,
  50. index: idx,
  51. indexes: [],
  52. lastCascade: false,
  53. lastSelect: false,
  54. listSet: false,
  55. name: undefined,
  56. redraw: false,
  57. rowData: {
  58. arrayFilter: [],
  59. arrayOriginal: [],
  60. arrayTotals: [],
  61. bins: {},
  62. binsOriginal: {},
  63. binsTotal: {},
  64. filterMap: new Map(),
  65. totalOptions: 0
  66. },
  67. scrollTop: 0,
  68. searchFunction: undefined,
  69. selectPresent: false,
  70. serverSelect: [],
  71. serverSelecting: false,
  72. showFiltered: false,
  73. tableLength: null,
  74. updating: false
  75. };
  76. var rowLength = table.columns().eq(0).toArray().length;
  77. this.colExists = this.s.index < rowLength;
  78. // Add extra elements to DOM object including clear and hide buttons
  79. this.c.layout = layout;
  80. var layVal = parseInt(layout.split('-')[1], 10);
  81. this.dom = {
  82. buttonGroup: $('<div/>').addClass(this.classes.buttonGroup),
  83. clear: $('<button type="button">&#215;</button>')
  84. .addClass(this.classes.disabledButton)
  85. .attr('disabled', 'true')
  86. .addClass(this.classes.paneButton)
  87. .addClass(this.classes.clearButton),
  88. container: $('<div/>')
  89. .addClass(this.classes.container)
  90. .addClass(this.classes.layout +
  91. (layVal < 10 ? layout : layout.split('-')[0] + '-9')),
  92. countButton: $('<button type="button"></button>')
  93. .addClass(this.classes.paneButton)
  94. .addClass(this.classes.countButton),
  95. dtP: $('<table><thead><tr><th>' +
  96. (this.colExists
  97. ? $(table.column(this.colExists ? this.s.index : 0).header()).text()
  98. : this.customPaneSettings.header || 'Custom Pane') + '</th><th/></tr></thead></table>'),
  99. lower: $('<div/>').addClass(this.classes.subRow2).addClass(this.classes.narrowButton),
  100. nameButton: $('<button type="button"></button>')
  101. .addClass(this.classes.paneButton)
  102. .addClass(this.classes.nameButton),
  103. panesContainer: panesContainer,
  104. searchBox: $('<input/>').addClass(this.classes.paneInputButton).addClass(this.classes.search),
  105. searchButton: $('<button type = "button" class="' + this.classes.searchIcon + '"></button>')
  106. .addClass(this.classes.paneButton),
  107. searchCont: $('<div/>').addClass(this.classes.searchCont),
  108. searchLabelCont: $('<div/>').addClass(this.classes.searchLabelCont),
  109. topRow: $('<div/>').addClass(this.classes.topRow),
  110. upper: $('<div/>').addClass(this.classes.subRow1).addClass(this.classes.narrowSearch)
  111. };
  112. this.s.displayed = false;
  113. table = this.s.dt;
  114. this.selections = [];
  115. this.s.colOpts = this.colExists ? this._getOptions() : this._getBonusOptions();
  116. var colOpts = this.s.colOpts;
  117. var clear = $('<button type="button">X</button>').addClass(this.classes.paneButton);
  118. $(clear).text(table.i18n('searchPanes.clearPane', this.c.i18n.clearPane));
  119. this.dom.container.addClass(colOpts.className);
  120. this.dom.container.addClass((this.customPaneSettings !== null && this.customPaneSettings.className !== undefined)
  121. ? this.customPaneSettings.className
  122. : '');
  123. // Set the value of name incase ordering is desired
  124. if (this.s.colOpts.name !== undefined) {
  125. this.s.name = this.s.colOpts.name;
  126. }
  127. else if (this.customPaneSettings !== null && this.customPaneSettings.name !== undefined) {
  128. this.s.name = this.customPaneSettings.name;
  129. }
  130. else {
  131. this.s.name = this.colExists ?
  132. $(table.column(this.s.index).header()).text() :
  133. this.customPaneSettings.header || 'Custom Pane';
  134. }
  135. $(panesContainer).append(this.dom.container);
  136. var tableNode = table.table(0).node();
  137. // Custom search function for table
  138. this.s.searchFunction = function (settings, searchData, dataIndex, origData) {
  139. // If no data has been selected then show all
  140. if (_this.selections.length === 0) {
  141. return true;
  142. }
  143. if (settings.nTable !== tableNode) {
  144. return true;
  145. }
  146. var filter = null;
  147. if (_this.colExists) {
  148. // Get the current filtered data
  149. filter = searchData[_this.s.index];
  150. if (colOpts.orthogonal.filter !== 'filter') {
  151. // get the filter value from the map
  152. filter = _this.s.rowData.filterMap.get(dataIndex);
  153. if (filter instanceof $.fn.dataTable.Api) {
  154. filter = filter.toArray();
  155. }
  156. }
  157. }
  158. return _this._search(filter, dataIndex);
  159. };
  160. $.fn.dataTable.ext.search.push(this.s.searchFunction);
  161. // If the clear button for this pane is clicked clear the selections
  162. if (this.c.clear) {
  163. $(clear).on('click', function () {
  164. var searches = _this.dom.container.find('.' + _this.classes.search.replace(/\s+/g, '.'));
  165. searches.each(function () {
  166. $(this).val('');
  167. $(this).trigger('input');
  168. });
  169. _this.clearPane();
  170. });
  171. }
  172. // Sometimes the top row of the panes containing the search box and ordering buttons appears
  173. // weird if the width of the panes is lower than expected, this fixes the design.
  174. // Equally this may occur when the table is resized.
  175. table.on('draw.dtsp', function () {
  176. _this.adjustTopRow();
  177. });
  178. table.on('buttons-action', function () {
  179. _this.adjustTopRow();
  180. });
  181. // When column-reorder is present and the columns are moved, it is necessary to
  182. // reassign all of the panes indexes to the new index of the column.
  183. table.on('column-reorder.dtsp', function (e, settings, details) {
  184. _this.s.index = details.mapping[_this.s.index];
  185. });
  186. return this;
  187. }
  188. /**
  189. * Adds a row to the panes table
  190. *
  191. * @param display the value to be displayed to the user
  192. * @param filter the value to be filtered on when searchpanes is implemented
  193. * @param shown the number of rows in the table that are currently visible matching this criteria
  194. * @param total the total number of rows in the table that match this criteria
  195. * @param sort the value to be sorted in the pane table
  196. * @param type the value of which the type is to be derived from
  197. */
  198. SearchPane.prototype.addRow = function (display, filter, shown, total, sort, type, className) {
  199. var index;
  200. for (var _i = 0, _a = this.s.indexes; _i < _a.length; _i++) {
  201. var entry = _a[_i];
  202. if (entry.filter === filter) {
  203. index = entry.index;
  204. }
  205. }
  206. if (index === undefined) {
  207. index = this.s.indexes.length;
  208. this.s.indexes.push({ filter: filter, index: index });
  209. }
  210. return this.s.dtPane.row.add({
  211. className: className,
  212. display: display !== '' ?
  213. display :
  214. this.emptyMessage(),
  215. filter: filter,
  216. index: index,
  217. shown: shown,
  218. sort: sort,
  219. total: total,
  220. type: type
  221. });
  222. };
  223. /**
  224. * Adjusts the layout of the top row when the screen is resized
  225. */
  226. SearchPane.prototype.adjustTopRow = function () {
  227. var subContainers = this.dom.container.find('.' + this.classes.subRowsContainer.replace(/\s+/g, '.'));
  228. var subRow1 = this.dom.container.find('.' + this.classes.subRow1.replace(/\s+/g, '.'));
  229. var subRow2 = this.dom.container.find('.' + this.classes.subRow2.replace(/\s+/g, '.'));
  230. var topRow = this.dom.container.find('.' + this.classes.topRow.replace(/\s+/g, '.'));
  231. // If the width is 0 then it is safe to assume that the pane has not yet been displayed.
  232. // Even if it has, if the width is 0 it won't make a difference if it has the narrow class or not
  233. if (($(subContainers[0]).width() < 252 || $(topRow[0]).width() < 252) && $(subContainers[0]).width() !== 0) {
  234. $(subContainers[0]).addClass(this.classes.narrow);
  235. $(subRow1[0]).addClass(this.classes.narrowSub).removeClass(this.classes.narrowSearch);
  236. $(subRow2[0]).addClass(this.classes.narrowSub).removeClass(this.classes.narrowButton);
  237. }
  238. else {
  239. $(subContainers[0]).removeClass(this.classes.narrow);
  240. $(subRow1[0]).removeClass(this.classes.narrowSub).addClass(this.classes.narrowSearch);
  241. $(subRow2[0]).removeClass(this.classes.narrowSub).addClass(this.classes.narrowButton);
  242. }
  243. };
  244. /**
  245. * In the case of a rebuild there is potential for new data to have been included or removed
  246. * so all of the rowData must be reset as a precaution.
  247. */
  248. SearchPane.prototype.clearData = function () {
  249. this.s.rowData = {
  250. arrayFilter: [],
  251. arrayOriginal: [],
  252. arrayTotals: [],
  253. bins: {},
  254. binsOriginal: {},
  255. binsTotal: {},
  256. filterMap: new Map(),
  257. totalOptions: 0
  258. };
  259. };
  260. /**
  261. * Clear the selections in the pane
  262. */
  263. SearchPane.prototype.clearPane = function () {
  264. // Deselect all rows which are selected and update the table and filter count.
  265. this.s.dtPane.rows({ selected: true }).deselect();
  266. this.updateTable();
  267. return this;
  268. };
  269. /**
  270. * Strips all of the SearchPanes elements from the document and turns all of the listeners for the buttons off
  271. */
  272. SearchPane.prototype.destroy = function () {
  273. $(this.s.dtPane).off('.dtsp');
  274. $(this.s.dt).off('.dtsp');
  275. $(this.dom.nameButton).off('.dtsp');
  276. $(this.dom.countButton).off('.dtsp');
  277. $(this.dom.clear).off('.dtsp');
  278. $(this.dom.searchButton).off('.dtsp');
  279. $(this.dom.container).remove();
  280. var searchIdx = $.fn.dataTable.ext.search.indexOf(this.s.searchFunction);
  281. while (searchIdx !== -1) {
  282. $.fn.dataTable.ext.search.splice(searchIdx, 1);
  283. searchIdx = $.fn.dataTable.ext.search.indexOf(this.s.searchFunction);
  284. }
  285. // If the datatables have been defined for the panes then also destroy these
  286. if (this.s.dtPane !== undefined) {
  287. this.s.dtPane.destroy();
  288. }
  289. this.s.listSet = false;
  290. };
  291. /**
  292. * Getting the legacy message is a little complex due a legacy parameter
  293. */
  294. SearchPane.prototype.emptyMessage = function () {
  295. var def = this.c.i18n.emptyMessage;
  296. // Legacy parameter support
  297. if (this.c.emptyMessage) {
  298. def = this.c.emptyMessage;
  299. }
  300. // Override per column
  301. if (this.s.colOpts.emptyMessage !== false && this.s.colOpts.emptyMessage !== null) {
  302. def = this.s.colOpts.emptyMessage;
  303. }
  304. return this.s.dt.i18n('searchPanes.emptyMessage', def);
  305. };
  306. /**
  307. * Updates the number of filters that have been applied in the title
  308. */
  309. SearchPane.prototype.getPaneCount = function () {
  310. return this.s.dtPane !== undefined ?
  311. this.s.dtPane.rows({ selected: true }).data().toArray().length :
  312. 0;
  313. };
  314. /**
  315. * Rebuilds the panes from the start having deleted the old ones
  316. *
  317. * @param? last boolean to indicate if this is the last pane a selection was made in
  318. * @param? dataIn data to be used in buildPane
  319. * @param? init Whether this is the initial draw or not
  320. * @param? maintainSelection Whether the current selections are to be maintained over rebuild
  321. */
  322. SearchPane.prototype.rebuildPane = function (last, dataIn, init, maintainSelection) {
  323. if (last === void 0) { last = false; }
  324. if (dataIn === void 0) { dataIn = null; }
  325. if (init === void 0) { init = null; }
  326. if (maintainSelection === void 0) { maintainSelection = false; }
  327. this.clearData();
  328. var selectedRows = [];
  329. this.s.serverSelect = [];
  330. var prevEl = null;
  331. // When rebuilding strip all of the HTML Elements out of the container and start from scratch
  332. if (this.s.dtPane !== undefined) {
  333. if (maintainSelection) {
  334. if (!this.s.dt.page.info().serverSide) {
  335. selectedRows = this.s.dtPane.rows({ selected: true }).data().toArray();
  336. }
  337. else {
  338. this.s.serverSelect = this.s.dtPane.rows({ selected: true }).data().toArray();
  339. }
  340. }
  341. this.s.dtPane.clear().destroy();
  342. prevEl = $(this.dom.container).prev();
  343. this.destroy();
  344. this.s.dtPane = undefined;
  345. $.fn.dataTable.ext.search.push(this.s.searchFunction);
  346. }
  347. this.dom.container.removeClass(this.classes.hidden);
  348. this.s.displayed = false;
  349. this._buildPane(!this.s.dt.page.info().serverSide ?
  350. selectedRows :
  351. this.s.serverSelect, last, dataIn, init, prevEl);
  352. return this;
  353. };
  354. /**
  355. * removes the pane from the page and sets the displayed property to false.
  356. */
  357. SearchPane.prototype.removePane = function () {
  358. this.s.displayed = false;
  359. $(this.dom.container).hide();
  360. };
  361. /**
  362. * Resizes the pane based on the layout that is passed in
  363. *
  364. * @param layout the layout to be applied to this pane
  365. */
  366. SearchPane.prototype.resize = function (layout) {
  367. this.c.layout = layout;
  368. var layVal = parseInt(layout.split('-')[1], 10);
  369. $(this.dom.container)
  370. .removeClass()
  371. .addClass(this.classes.container)
  372. .addClass(this.classes.layout +
  373. (layVal < 10 ? layout : layout.split('-')[0] + '-9'))
  374. .addClass(this.s.colOpts.className)
  375. .addClass((this.customPaneSettings !== null && this.customPaneSettings.className !== undefined)
  376. ? this.customPaneSettings.className
  377. : '')
  378. .addClass(this.classes.show);
  379. this.adjustTopRow();
  380. };
  381. /**
  382. * Sets the cascadeRegen property of the pane. Accessible from above because as SearchPanes.ts
  383. * deals with the rebuilds.
  384. *
  385. * @param val the boolean value that the cascadeRegen property is to be set to
  386. */
  387. SearchPane.prototype.setCascadeRegen = function (val) {
  388. this.s.cascadeRegen = val;
  389. };
  390. /**
  391. * This function allows the clearing property to be assigned. This is used when implementing cascadePane.
  392. * In setting this to true for the clearing of the panes selection on the deselects it forces the pane to
  393. * repopulate from the entire dataset not just the displayed values.
  394. *
  395. * @param val the boolean value which the clearing property is to be assigned
  396. */
  397. SearchPane.prototype.setClear = function (val) {
  398. this.s.clearing = val;
  399. };
  400. /**
  401. * Updates the values of all of the panes
  402. *
  403. * @param draw whether this has been triggered by a draw event or not
  404. */
  405. SearchPane.prototype.updatePane = function (draw) {
  406. if (draw === void 0) { draw = false; }
  407. this.s.updating = true;
  408. this._updateCommon(draw);
  409. this.s.updating = false;
  410. };
  411. /**
  412. * Updates the panes if one of the options to do so has been set to true
  413. * rather than the filtered message when using viewTotal.
  414. */
  415. SearchPane.prototype.updateTable = function () {
  416. var selectedRows = this.s.dtPane.rows({ selected: true }).data().toArray();
  417. this.selections = selectedRows;
  418. this._searchExtras();
  419. // If either of the options that effect how the panes are displayed are selected then update the Panes
  420. if (this.c.cascadePanes || this.c.viewTotal) {
  421. this.updatePane();
  422. }
  423. };
  424. /**
  425. * Sets the listeners for the pane.
  426. *
  427. * Having it in it's own function makes it easier to only set them once
  428. */
  429. SearchPane.prototype._setListeners = function () {
  430. var _this = this;
  431. var rowData = this.s.rowData;
  432. var t0;
  433. // When an item is selected on the pane, add these to the array which holds selected items.
  434. // Custom search will perform.
  435. this.s.dtPane.on('select.dtsp', function () {
  436. clearTimeout(t0);
  437. if (_this.s.dt.page.info().serverSide && !_this.s.updating) {
  438. if (!_this.s.serverSelecting) {
  439. _this.s.serverSelect = _this.s.dtPane.rows({ selected: true }).data().toArray();
  440. _this.s.scrollTop = $(_this.s.dtPane.table().node()).parent()[0].scrollTop;
  441. _this.s.selectPresent = true;
  442. _this.s.dt.draw(false);
  443. }
  444. }
  445. else {
  446. $(_this.dom.clear).removeClass(_this.classes.disabledButton).removeAttr('disabled');
  447. if (!_this.s.updating) {
  448. _this.s.selectPresent = true;
  449. _this._makeSelection();
  450. _this.s.selectPresent = false;
  451. }
  452. }
  453. });
  454. // When an item is deselected on the pane, re add the currently selected items to the array
  455. // which holds selected items. Custom search will be performed.
  456. this.s.dtPane.on('deselect.dtsp', function () {
  457. t0 = setTimeout(function () {
  458. if (_this.s.dt.page.info().serverSide && !_this.s.updating) {
  459. if (!_this.s.serverSelecting) {
  460. _this.s.serverSelect = _this.s.dtPane.rows({ selected: true }).data().toArray();
  461. _this.s.deselect = true;
  462. _this.s.dt.draw(false);
  463. }
  464. }
  465. else {
  466. _this.s.deselect = true;
  467. if (_this.s.dtPane.rows({ selected: true }).data().toArray().length === 0) {
  468. $(_this.dom.clear).addClass(_this.classes.disabledButton).attr('disabled', 'true');
  469. }
  470. _this._makeSelection();
  471. _this.s.deselect = false;
  472. _this.s.dt.state.save();
  473. }
  474. }, 50);
  475. });
  476. // When saving the state store all of the selected rows for preselection next time around
  477. this.s.dt.on('stateSaveParams.dtsp', function (e, settings, data) {
  478. // If the data being passed in is empty then state clear must have occured so clear the panes state as well
  479. if ($.isEmptyObject(data)) {
  480. _this.s.dtPane.state.clear();
  481. return;
  482. }
  483. var selected = [];
  484. var searchTerm;
  485. var order;
  486. var bins;
  487. var arrayFilter;
  488. // Get all of the data needed for the state save from the pane
  489. if (_this.s.dtPane !== undefined) {
  490. selected = _this.s.dtPane.rows({ selected: true }).data().map(function (item) { return item.filter.toString(); }).toArray();
  491. searchTerm = $(_this.dom.searchBox).val();
  492. order = _this.s.dtPane.order();
  493. bins = rowData.binsOriginal;
  494. arrayFilter = rowData.arrayOriginal;
  495. }
  496. if (data.searchPanes === undefined) {
  497. data.searchPanes = {};
  498. }
  499. if (data.searchPanes.panes === undefined) {
  500. data.searchPanes.panes = [];
  501. }
  502. for (var i = 0; i < data.searchPanes.panes.length; i++) {
  503. if (data.searchPanes.panes[i].id === _this.s.index) {
  504. data.searchPanes.panes.splice(i, 1);
  505. i--;
  506. }
  507. }
  508. // Add the panes data to the state object
  509. data.searchPanes.panes.push({
  510. arrayFilter: arrayFilter,
  511. bins: bins,
  512. id: _this.s.index,
  513. order: order,
  514. searchTerm: searchTerm,
  515. selected: selected
  516. });
  517. });
  518. this.s.dtPane.on('user-select.dtsp', function (e, _dt, type, cell, originalEvent) {
  519. originalEvent.stopPropagation();
  520. });
  521. this.s.dtPane.on('draw.dtsp', function () {
  522. _this.adjustTopRow();
  523. });
  524. // When the button to order by the name of the options is clicked then
  525. // change the ordering to whatever it isn't currently
  526. $(this.dom.nameButton).on('click.dtsp', function () {
  527. var currentOrder = _this.s.dtPane.order()[0][1];
  528. _this.s.dtPane.order([0, currentOrder === 'asc' ? 'desc' : 'asc']).draw();
  529. _this.s.dt.state.save();
  530. });
  531. // When the button to order by the number of entries in the column is clicked then
  532. // change the ordering to whatever it isn't currently
  533. $(this.dom.countButton).on('click.dtsp', function () {
  534. var currentOrder = _this.s.dtPane.order()[0][1];
  535. _this.s.dtPane.order([1, currentOrder === 'asc' ? 'desc' : 'asc']).draw();
  536. _this.s.dt.state.save();
  537. });
  538. // When the clear button is clicked reset the pane
  539. $(this.dom.clear).on('click.dtsp', function () {
  540. var searches = _this.dom.container.find('.' + _this.classes.search.replace(/ /g, '.'));
  541. searches.each(function () {
  542. // set the value of the search box to be an empty string and then search on that, effectively reseting
  543. $(this).val('');
  544. $(this).trigger('input');
  545. });
  546. _this.clearPane();
  547. });
  548. // When the search button is clicked then draw focus to the search box
  549. $(this.dom.searchButton).on('click.dtsp', function () {
  550. $(_this.dom.searchBox).focus();
  551. });
  552. // When a character is inputted into the searchbox search the pane for matching values.
  553. // Doing it this way means that no button has to be clicked to trigger a search, it is done asynchronously
  554. $(this.dom.searchBox).on('input.dtsp', function () {
  555. var searchval = $(_this.dom.searchBox).val();
  556. _this.s.dtPane.search(searchval).draw();
  557. if (searchval.length > 0 ||
  558. (searchval.length === 0 && _this.s.dtPane.rows({ selected: true }).data().toArray().length > 0)) {
  559. _this.dom.clear.removeClass(_this.classes.disabledButton).removeAttr('disabled');
  560. }
  561. else {
  562. _this.dom.clear.addClass(_this.classes.disabledButton).attr('disabled', 'true');
  563. }
  564. _this.s.dt.state.save();
  565. });
  566. // Make sure to save the state once the pane has been built
  567. this.s.dt.state.save();
  568. return true;
  569. };
  570. /**
  571. * Takes in potentially undetected rows and adds them to the array if they are not yet featured
  572. *
  573. * @param filter the filter value of the potential row
  574. * @param display the display value of the potential row
  575. * @param sort the sort value of the potential row
  576. * @param type the type value of the potential row
  577. * @param arrayFilter the array to be populated
  578. * @param bins the bins to be populated
  579. */
  580. SearchPane.prototype._addOption = function (filter, display, sort, type, arrayFilter, bins) {
  581. // If the filter is an array then take a note of this, and add the elements to the arrayFilter array
  582. if (Array.isArray(filter) || filter instanceof dataTable.Api) {
  583. // Convert to an array so that we can work with it
  584. if (filter instanceof dataTable.Api) {
  585. filter = filter.toArray();
  586. display = display.toArray();
  587. }
  588. if (filter.length === display.length) {
  589. for (var i = 0; i < filter.length; i++) {
  590. // If we haven't seen this row before add it
  591. if (!bins[filter[i]]) {
  592. bins[filter[i]] = 1;
  593. arrayFilter.push({
  594. display: display[i],
  595. filter: filter[i],
  596. sort: sort[i],
  597. type: type[i]
  598. });
  599. }
  600. // Otherwise just increment the count
  601. else {
  602. bins[filter[i]]++;
  603. }
  604. this.s.rowData.totalOptions++;
  605. }
  606. return;
  607. }
  608. else {
  609. throw new Error('display and filter not the same length');
  610. }
  611. }
  612. // If the values were affected by othogonal data and are not an array then check if it is already present
  613. else if (typeof this.s.colOpts.orthogonal === 'string') {
  614. if (!bins[filter]) {
  615. bins[filter] = 1;
  616. arrayFilter.push({
  617. display: display,
  618. filter: filter,
  619. sort: sort,
  620. type: type
  621. });
  622. this.s.rowData.totalOptions++;
  623. }
  624. else {
  625. bins[filter]++;
  626. this.s.rowData.totalOptions++;
  627. return;
  628. }
  629. }
  630. // Otherwise we must just be adding an option
  631. else {
  632. arrayFilter.push({
  633. display: display,
  634. filter: filter,
  635. sort: sort,
  636. type: type
  637. });
  638. }
  639. };
  640. /**
  641. * Method to construct the actual pane.
  642. *
  643. * @param selectedRows previously selected Rows to be reselected
  644. * @last boolean to indicate whether this pane was the last one to have a selection made
  645. */
  646. SearchPane.prototype._buildPane = function (selectedRows, last, dataIn, init, prevEl) {
  647. var _this = this;
  648. if (selectedRows === void 0) { selectedRows = []; }
  649. if (last === void 0) { last = false; }
  650. if (dataIn === void 0) { dataIn = null; }
  651. if (init === void 0) { init = null; }
  652. if (prevEl === void 0) { prevEl = null; }
  653. // Aliases
  654. this.selections = [];
  655. var table = this.s.dt;
  656. var column = table.column(this.colExists ? this.s.index : 0);
  657. var colOpts = this.s.colOpts;
  658. var rowData = this.s.rowData;
  659. // Other Variables
  660. var countMessage = table.i18n('searchPanes.count', this.c.i18n.count);
  661. var filteredMessage = table.i18n('searchPanes.countFiltered', this.c.i18n.countFiltered);
  662. var loadedFilter = table.state.loaded();
  663. // If the listeners have not been set yet then using the latest state may result in funny errors
  664. if (this.s.listSet) {
  665. loadedFilter = table.state();
  666. }
  667. // If it is not a custom pane in place
  668. if (this.colExists) {
  669. var idx = -1;
  670. if (loadedFilter && loadedFilter.searchPanes && loadedFilter.searchPanes.panes) {
  671. for (var i = 0; i < loadedFilter.searchPanes.panes.length; i++) {
  672. if (loadedFilter.searchPanes.panes[i].id === this.s.index) {
  673. idx = i;
  674. break;
  675. }
  676. }
  677. }
  678. // Perform checks that do not require populate pane to run
  679. if ((colOpts.show === false
  680. || (colOpts.show !== undefined && colOpts.show !== true)) &&
  681. idx === -1) {
  682. this.dom.container.addClass(this.classes.hidden);
  683. this.s.displayed = false;
  684. return false;
  685. }
  686. else if (colOpts.show === true || idx !== -1) {
  687. this.s.displayed = true;
  688. }
  689. if (!this.s.dt.page.info().serverSide &&
  690. (dataIn === null ||
  691. dataIn.searchPanes === null ||
  692. dataIn.searchPanes.options === null)) {
  693. // Only run populatePane if the data has not been collected yet
  694. if (rowData.arrayFilter.length === 0) {
  695. this._populatePane(last);
  696. this.s.rowData.totalOptions = 0;
  697. this._detailsPane();
  698. // If the index is not found then no data has been added to the state for this pane,
  699. // which will only occur if it has previously failed to meet the criteria to be
  700. // displayed, therefore we can just hide it again here
  701. if (loadedFilter && loadedFilter.searchPanes && loadedFilter.searchPanes.panes && idx === -1) {
  702. this.dom.container.addClass(this.classes.hidden);
  703. this.s.displayed = false;
  704. return;
  705. }
  706. rowData.arrayOriginal = rowData.arrayTotals;
  707. rowData.binsOriginal = rowData.binsTotal;
  708. }
  709. var binLength = Object.keys(rowData.binsOriginal).length;
  710. var uniqueRatio = this._uniqueRatio(binLength, table.rows()[0].length);
  711. // Don't show the pane if there isn't enough variance in the data, or there is only 1 entry
  712. // for that pane
  713. if (this.s.displayed === false && ((colOpts.show === undefined && colOpts.threshold === null ?
  714. uniqueRatio > this.c.threshold :
  715. uniqueRatio > colOpts.threshold)
  716. || (colOpts.show !== true && binLength <= 1))) {
  717. this.dom.container.addClass(this.classes.hidden);
  718. this.s.displayed = false;
  719. return;
  720. }
  721. // If the option viewTotal is true then find
  722. // the total count for the whole table to display alongside the displayed count
  723. if (this.c.viewTotal && rowData.arrayTotals.length === 0) {
  724. this.s.rowData.totalOptions = 0;
  725. this._detailsPane();
  726. }
  727. else {
  728. rowData.binsTotal = rowData.bins;
  729. }
  730. this.dom.container.addClass(this.classes.show);
  731. this.s.displayed = true;
  732. }
  733. else if (dataIn !== null && dataIn.searchPanes !== null && dataIn.searchPanes.options !== null) {
  734. if (dataIn.tableLength !== undefined) {
  735. this.s.tableLength = dataIn.tableLength;
  736. this.s.rowData.totalOptions = this.s.tableLength;
  737. }
  738. else if (this.s.tableLength === null || table.rows()[0].length > this.s.tableLength) {
  739. this.s.tableLength = table.rows()[0].length;
  740. this.s.rowData.totalOptions = this.s.tableLength;
  741. }
  742. var colTitle = table.column(this.s.index).dataSrc();
  743. if (dataIn.searchPanes.options[colTitle] !== undefined) {
  744. for (var _i = 0, _a = dataIn.searchPanes.options[colTitle]; _i < _a.length; _i++) {
  745. var dataPoint = _a[_i];
  746. this.s.rowData.arrayFilter.push({
  747. display: dataPoint.label,
  748. filter: dataPoint.value,
  749. sort: dataPoint.label,
  750. type: dataPoint.label
  751. });
  752. this.s.rowData.bins[dataPoint.value] = this.c.viewTotal || this.c.cascadePanes ?
  753. dataPoint.count :
  754. dataPoint.total;
  755. this.s.rowData.binsTotal[dataPoint.value] = dataPoint.total;
  756. }
  757. }
  758. var binLength = Object.keys(rowData.binsTotal).length;
  759. var uniqueRatio = this._uniqueRatio(binLength, this.s.tableLength);
  760. // Don't show the pane if there isnt enough variance in the data, or there is only 1 entry for that pane
  761. if (this.s.displayed === false && ((colOpts.show === undefined && colOpts.threshold === null ?
  762. uniqueRatio > this.c.threshold :
  763. uniqueRatio > colOpts.threshold)
  764. || (colOpts.show !== true && binLength <= 1))) {
  765. this.dom.container.addClass(this.classes.hidden);
  766. this.s.displayed = false;
  767. return;
  768. }
  769. this.s.rowData.arrayOriginal = this.s.rowData.arrayFilter;
  770. this.s.rowData.binsOriginal = this.s.rowData.bins;
  771. this.s.displayed = true;
  772. }
  773. }
  774. else {
  775. this.s.displayed = true;
  776. }
  777. // If the variance is accceptable then display the search pane
  778. this._displayPane();
  779. if (!this.s.listSet) {
  780. // Here, when the state is loaded if the data object on the original table is empty,
  781. // then a state.clear() must have occurred, so delete all of the panes tables state objects too.
  782. this.dom.dtP.on('stateLoadParams.dt', function (e, settings, data) {
  783. if ($.isEmptyObject(table.state.loaded())) {
  784. $.each(data, function (index, value) {
  785. delete data[index];
  786. });
  787. }
  788. });
  789. }
  790. // Add the container to the document in its original location
  791. if (prevEl !== null && $(this.dom.panesContainer).has(prevEl).length > 0) {
  792. $(this.dom.container).insertAfter(prevEl);
  793. }
  794. else {
  795. $(this.dom.panesContainer).prepend(this.dom.container);
  796. }
  797. // Declare the datatable for the pane
  798. var errMode = $.fn.dataTable.ext.errMode;
  799. $.fn.dataTable.ext.errMode = 'none';
  800. var haveScroller = dataTable.Scroller;
  801. this.s.dtPane = $(this.dom.dtP).DataTable($.extend(true, {
  802. columnDefs: [
  803. {
  804. className: 'dtsp-nameColumn',
  805. data: 'display',
  806. render: function (data, type, row) {
  807. if (type === 'sort') {
  808. return row.sort;
  809. }
  810. else if (type === 'type') {
  811. return row.type;
  812. }
  813. var message;
  814. message = ((_this.s.filteringActive || _this.s.showFiltered) && _this.c.viewTotal) ||
  815. (_this.c.viewTotal && _this.s.forceViewTotal) ?
  816. filteredMessage.replace(/{total}/, row.total) :
  817. countMessage.replace(/{total}/, row.total);
  818. message = message.replace(/{shown}/, row.shown);
  819. while (message.indexOf('{total}') !== -1) {
  820. message = message.replace(/{total}/, row.total);
  821. }
  822. while (message.indexOf('{shown}') !== -1) {
  823. message = message.replace(/{shown}/, row.shown);
  824. }
  825. // We are displaying the count in the same columne as the name of the search option.
  826. // This is so that there is not need to call columns.adjust()
  827. // which in turn speeds up the code
  828. var pill = '<span class="' + _this.classes.pill + '">' + message + '</span>';
  829. if (!_this.c.viewCount || !colOpts.viewCount) {
  830. pill = '';
  831. }
  832. if (type === 'filter') {
  833. return typeof data === 'string' && data.match(/<[^>]*>/) !== null ?
  834. data.replace(/<[^>]*>/g, '') :
  835. data;
  836. }
  837. return '<div class="' + _this.classes.nameCont + '"><span title="' +
  838. (typeof data === 'string' && data.match(/<[^>]*>/) !== null ?
  839. data.replace(/<[^>]*>/g, '') :
  840. data) +
  841. '" class="' + _this.classes.name + '">' +
  842. data + '</span>' +
  843. pill + '</div>';
  844. },
  845. targets: 0,
  846. // Accessing the private datatables property to set type based on the original table.
  847. // This is null if not defined by the user, meaning that automatic type detection
  848. // would take place
  849. type: table.settings()[0].aoColumns[this.s.index] !== undefined ?
  850. table.settings()[0].aoColumns[this.s.index]._sManualType :
  851. null
  852. },
  853. {
  854. className: 'dtsp-countColumn ' + this.classes.badgePill,
  855. data: 'shown',
  856. orderData: [1, 2],
  857. targets: 1,
  858. visible: false
  859. },
  860. {
  861. data: 'total',
  862. targets: 2,
  863. visible: false
  864. }
  865. ],
  866. deferRender: true,
  867. dom: 't',
  868. info: false,
  869. language: this.s.dt.settings()[0].oLanguage,
  870. paging: haveScroller ? true : false,
  871. scrollX: false,
  872. scrollY: '200px',
  873. scroller: haveScroller ? true : false,
  874. select: true,
  875. stateSave: table.settings()[0].oFeatures.bStateSave ? true : false
  876. }, this.c.dtOpts, colOpts !== undefined ? colOpts.dtOpts : {}, (this.s.colOpts.options !== undefined || !this.colExists)
  877. ? {
  878. createdRow: function (row, data, dataIndex) {
  879. $(row).addClass(data.className);
  880. }
  881. }
  882. : undefined, (this.customPaneSettings !== null && this.customPaneSettings.dtOpts !== undefined)
  883. ? this.customPaneSettings.dtOpts
  884. : {}, $.fn.dataTable.versionCheck('2')
  885. ? {
  886. layout: {
  887. bottomLeft: null,
  888. bottomRight: null,
  889. topLeft: null,
  890. topRight: null
  891. }
  892. }
  893. : {}));
  894. $(this.dom.dtP).addClass(this.classes.table);
  895. // Getting column titles is a little messy
  896. var headerText = 'Custom Pane';
  897. if (this.customPaneSettings && this.customPaneSettings.header) {
  898. headerText = this.customPaneSettings.header;
  899. }
  900. else if (colOpts.header) {
  901. headerText = colOpts.header;
  902. }
  903. else if (this.colExists) {
  904. headerText = $.fn.dataTable.versionCheck('2')
  905. ? table.column(this.s.index).title()
  906. : table.settings()[0].aoColumns[this.s.index].sTitle;
  907. }
  908. this.dom.searchBox.attr('placeholder', headerText);
  909. // As the pane table is not in the document yet we must initialise select ourselves
  910. $.fn.dataTable.select.init(this.s.dtPane);
  911. $.fn.dataTable.ext.errMode = errMode;
  912. // If it is not a custom pane
  913. if (this.colExists) {
  914. // On initialisation, do we need to set a filtering value from a
  915. // saved state or init option?
  916. var search = column.search();
  917. search = search ? search.substr(1, search.length - 2).split('|') : [];
  918. // Count the number of empty cells
  919. var count_1 = 0;
  920. rowData.arrayFilter.forEach(function (element) {
  921. if (element.filter === '') {
  922. count_1++;
  923. }
  924. });
  925. // Add all of the search options to the pane
  926. for (var i = 0, ien = rowData.arrayFilter.length; i < ien; i++) {
  927. var selected = false;
  928. for (var _b = 0, _c = this.s.serverSelect; _b < _c.length; _b++) {
  929. var option = _c[_b];
  930. if (option.filter === rowData.arrayFilter[i].filter) {
  931. selected = true;
  932. }
  933. }
  934. if (this.s.dt.page.info().serverSide &&
  935. (!this.c.cascadePanes ||
  936. (this.c.cascadePanes && rowData.bins[rowData.arrayFilter[i].filter] !== 0) ||
  937. (this.c.cascadePanes && init !== null) ||
  938. selected)) {
  939. var row = this.addRow(rowData.arrayFilter[i].display, rowData.arrayFilter[i].filter, init ?
  940. rowData.binsTotal[rowData.arrayFilter[i].filter] :
  941. rowData.bins[rowData.arrayFilter[i].filter], this.c.viewTotal || init
  942. ? String(rowData.binsTotal[rowData.arrayFilter[i].filter])
  943. : rowData.bins[rowData.arrayFilter[i].filter], rowData.arrayFilter[i].sort, rowData.arrayFilter[i].type);
  944. for (var _d = 0, _e = this.s.serverSelect; _d < _e.length; _d++) {
  945. var option = _e[_d];
  946. if (option.filter === rowData.arrayFilter[i].filter) {
  947. this.s.serverSelecting = true;
  948. row.select();
  949. this.s.serverSelecting = false;
  950. }
  951. }
  952. }
  953. else if (!this.s.dt.page.info().serverSide &&
  954. rowData.arrayFilter[i] &&
  955. (rowData.bins[rowData.arrayFilter[i].filter] !== undefined || !this.c.cascadePanes)) {
  956. this.addRow(rowData.arrayFilter[i].display, rowData.arrayFilter[i].filter, rowData.bins[rowData.arrayFilter[i].filter], rowData.binsTotal[rowData.arrayFilter[i].filter], rowData.arrayFilter[i].sort, rowData.arrayFilter[i].type);
  957. }
  958. else if (!this.s.dt.page.info().serverSide) {
  959. // Just pass an empty string as the message will be calculated based on that in addRow()
  960. this.addRow('', count_1, count_1, '', '', '');
  961. }
  962. }
  963. }
  964. dataTable.select.init(this.s.dtPane);
  965. // If there are custom options set or it is a custom pane then get them
  966. if (colOpts.options !== undefined ||
  967. (this.customPaneSettings !== null && this.customPaneSettings.options !== undefined)) {
  968. this._getComparisonRows();
  969. }
  970. // Display the pane
  971. this.s.dtPane.draw();
  972. this.adjustTopRow();
  973. if (!this.s.listSet) {
  974. this._setListeners();
  975. this.s.listSet = true;
  976. }
  977. for (var _f = 0, selectedRows_1 = selectedRows; _f < selectedRows_1.length; _f++) {
  978. var selection = selectedRows_1[_f];
  979. if (selection !== undefined) {
  980. for (var _g = 0, _h = this.s.dtPane.rows().indexes().toArray(); _g < _h.length; _g++) {
  981. var row = _h[_g];
  982. if (this.s.dtPane.row(row).data() !== undefined &&
  983. selection.filter === this.s.dtPane.row(row).data().filter) {
  984. // If this is happening when serverSide processing is happening then
  985. // different behaviour is needed
  986. if (this.s.dt.page.info().serverSide) {
  987. this.s.serverSelecting = true;
  988. this.s.dtPane.row(row).select();
  989. this.s.serverSelecting = false;
  990. }
  991. else {
  992. this.s.dtPane.row(row).select();
  993. }
  994. }
  995. }
  996. }
  997. }
  998. // If SSP and the table is ready, apply the search for the pane
  999. if (this.s.dt.page.info().serverSide) {
  1000. this.s.dtPane.search($(this.dom.searchBox).val()).draw();
  1001. }
  1002. // Reload the selection, searchbox entry and ordering from the previous state
  1003. // Need to check here if SSP that this is the first draw, otherwise it will infinite loop
  1004. if (loadedFilter &&
  1005. loadedFilter.searchPanes &&
  1006. loadedFilter.searchPanes.panes &&
  1007. (dataIn === null ||
  1008. dataIn.draw === 1)) {
  1009. if (!this.c.cascadePanes) {
  1010. this._reloadSelect(loadedFilter);
  1011. }
  1012. for (var _j = 0, _k = loadedFilter.searchPanes.panes; _j < _k.length; _j++) {
  1013. var pane = _k[_j];
  1014. if (pane.id === this.s.index) {
  1015. $(this.dom.searchBox).val(pane.searchTerm);
  1016. $(this.dom.searchBox).trigger('input');
  1017. this.s.dtPane.order(pane.order).draw();
  1018. }
  1019. }
  1020. }
  1021. // Make sure to save the state once the pane has been built
  1022. this.s.dt.state.save();
  1023. return true;
  1024. };
  1025. /**
  1026. * Update the array which holds the display and filter values for the table
  1027. */
  1028. SearchPane.prototype._detailsPane = function () {
  1029. var table = this.s.dt;
  1030. this.s.rowData.arrayTotals = [];
  1031. this.s.rowData.binsTotal = {};
  1032. var settings = this.s.dt.settings()[0];
  1033. var indexArray = table.rows().indexes();
  1034. if (!this.s.dt.page.info().serverSide) {
  1035. for (var _i = 0, indexArray_1 = indexArray; _i < indexArray_1.length; _i++) {
  1036. var rowIdx = indexArray_1[_i];
  1037. this._populatePaneArray(rowIdx, this.s.rowData.arrayTotals, settings, this.s.rowData.binsTotal);
  1038. }
  1039. }
  1040. };
  1041. /**
  1042. * Appends all of the HTML elements to their relevant parent Elements
  1043. */
  1044. SearchPane.prototype._displayPane = function () {
  1045. var container = this.dom.container;
  1046. var colOpts = this.s.colOpts;
  1047. var layVal = parseInt(this.c.layout.split('-')[1], 10);
  1048. // Empty everything to start again
  1049. $(this.dom.topRow).empty();
  1050. $(this.dom.dtP).empty();
  1051. $(this.dom.topRow).addClass(this.classes.topRow);
  1052. // If there are more than 3 columns defined then make there be a smaller gap between the panes
  1053. if (layVal > 3) {
  1054. $(this.dom.container).addClass(this.classes.smallGap);
  1055. }
  1056. $(this.dom.topRow).addClass(this.classes.subRowsContainer);
  1057. $(this.dom.upper).appendTo(this.dom.topRow);
  1058. $(this.dom.lower).appendTo(this.dom.topRow);
  1059. $(this.dom.searchCont).appendTo(this.dom.upper);
  1060. $(this.dom.buttonGroup).appendTo(this.dom.lower);
  1061. // If no selections have been made in the pane then disable the clear button
  1062. if (this.c.dtOpts.searching === false ||
  1063. (colOpts.dtOpts !== undefined &&
  1064. colOpts.dtOpts.searching === false) ||
  1065. (!this.c.controls || !colOpts.controls) ||
  1066. (this.customPaneSettings !== null &&
  1067. this.customPaneSettings.dtOpts !== undefined &&
  1068. this.customPaneSettings.dtOpts.searching !== undefined &&
  1069. !this.customPaneSettings.dtOpts.searching)) {
  1070. $(this.dom.searchBox)
  1071. .removeClass(this.classes.paneInputButton)
  1072. .addClass(this.classes.disabledButton)
  1073. .attr('disabled', 'true');
  1074. }
  1075. $(this.dom.searchBox).appendTo(this.dom.searchCont);
  1076. // Create the contents of the searchCont div. Worth noting that this function will change when using semantic ui
  1077. this._searchContSetup();
  1078. // If the clear button is allowed to show then display it
  1079. if (this.c.clear && this.c.controls && colOpts.controls) {
  1080. $(this.dom.clear).appendTo(this.dom.buttonGroup);
  1081. }
  1082. if (this.c.orderable && colOpts.orderable && this.c.controls && colOpts.controls) {
  1083. $(this.dom.nameButton).appendTo(this.dom.buttonGroup);
  1084. }
  1085. // If the count column is hidden then don't display the ordering button for it
  1086. if (this.c.viewCount &&
  1087. colOpts.viewCount &&
  1088. this.c.orderable &&
  1089. colOpts.orderable &&
  1090. this.c.controls &&
  1091. colOpts.controls) {
  1092. $(this.dom.countButton).appendTo(this.dom.buttonGroup);
  1093. }
  1094. $(this.dom.topRow).prependTo(this.dom.container);
  1095. $(container).append(this.dom.dtP);
  1096. $(container).show();
  1097. };
  1098. /**
  1099. * Gets the options for the row for the customPanes
  1100. *
  1101. * @returns {object} The options for the row extended to include the options from the user.
  1102. */
  1103. SearchPane.prototype._getBonusOptions = function () {
  1104. // We need to reset the thresholds as if they have a value in colOpts then that value will be used
  1105. var defaultMutator = {
  1106. orthogonal: {
  1107. threshold: null
  1108. },
  1109. threshold: null
  1110. };
  1111. return $.extend(true, {}, SearchPane.defaults, defaultMutator, this.c !== undefined ? this.c : {});
  1112. };
  1113. /**
  1114. * Adds the custom options to the pane
  1115. *
  1116. * @returns {Array} Returns the array of rows which have been added to the pane
  1117. */
  1118. SearchPane.prototype._getComparisonRows = function () {
  1119. var colOpts = this.s.colOpts;
  1120. // Find the appropriate options depending on whether this is a pane for a specific column or a custom pane
  1121. var options = colOpts.options !== undefined
  1122. ? colOpts.options
  1123. : this.customPaneSettings !== null && this.customPaneSettings.options !== undefined
  1124. ? this.customPaneSettings.options
  1125. : undefined;
  1126. if (options === undefined) {
  1127. return;
  1128. }
  1129. var tableVals = this.s.dt.rows({ search: 'applied' }).data().toArray();
  1130. var appRows = this.s.dt.rows({ search: 'applied' });
  1131. var tableValsTotal = this.s.dt.rows().data().toArray();
  1132. var allRows = this.s.dt.rows();
  1133. var rows = [];
  1134. // Clear all of the other rows from the pane, only custom options are to be displayed when they are defined
  1135. this.s.dtPane.clear();
  1136. for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
  1137. var comp = options_1[_i];
  1138. // Initialise the object which is to be placed in the row
  1139. var insert = comp.label !== '' ?
  1140. comp.label :
  1141. this.emptyMessage();
  1142. var comparisonObj = {
  1143. className: comp.className,
  1144. display: insert,
  1145. filter: typeof comp.value === 'function' ? comp.value : [],
  1146. shown: 0,
  1147. sort: insert,
  1148. total: 0,
  1149. type: insert
  1150. };
  1151. // If a custom function is in place
  1152. if (typeof comp.value === 'function') {
  1153. // Count the number of times the function evaluates to true for the data currently being displayed
  1154. for (var tVal = 0; tVal < tableVals.length; tVal++) {
  1155. if (comp.value.call(this.s.dt, tableVals[tVal], appRows[0][tVal])) {
  1156. comparisonObj.shown++;
  1157. }
  1158. }
  1159. // Count the number of times the function evaluates to true for the original data in the Table
  1160. for (var i = 0; i < tableValsTotal.length; i++) {
  1161. if (comp.value.call(this.s.dt, tableValsTotal[i], allRows[0][i])) {
  1162. comparisonObj.total++;
  1163. }
  1164. }
  1165. // Update the comparisonObj
  1166. if (typeof comparisonObj.filter !== 'function') {
  1167. comparisonObj.filter.push(comp.filter);
  1168. }
  1169. }
  1170. // If cascadePanes is not active or if it is and the comparisonObj should be shown then add it to the pane
  1171. if (!this.c.cascadePanes || (this.c.cascadePanes && comparisonObj.shown !== 0)) {
  1172. rows.push(this.addRow(comparisonObj.display, comparisonObj.filter, comparisonObj.shown, comparisonObj.total, comparisonObj.sort, comparisonObj.type, comparisonObj.className));
  1173. }
  1174. }
  1175. return rows;
  1176. };
  1177. /**
  1178. * Gets the options for the row for the customPanes
  1179. *
  1180. * @returns {object} The options for the row extended to include the options from the user.
  1181. */
  1182. SearchPane.prototype._getOptions = function () {
  1183. var table = this.s.dt;
  1184. // We need to reset the thresholds as if they have a value in colOpts then that value will be used
  1185. var defaultMutator = {
  1186. emptyMessage: false,
  1187. orthogonal: {
  1188. threshold: null
  1189. },
  1190. threshold: null
  1191. };
  1192. var columnOptions = table.settings()[0].aoColumns[this.s.index].searchPanes;
  1193. var colOpts = $.extend(true, {}, SearchPane.defaults, defaultMutator, columnOptions);
  1194. if (columnOptions !== undefined &&
  1195. columnOptions.hideCount !== undefined &&
  1196. columnOptions.viewCount === undefined) {
  1197. colOpts.viewCount = !columnOptions.hideCount;
  1198. }
  1199. return colOpts;
  1200. };
  1201. /**
  1202. * This method allows for changes to the panes and table to be made when a selection or a deselection occurs
  1203. *
  1204. * @param select Denotes whether a selection has been made or not
  1205. */
  1206. SearchPane.prototype._makeSelection = function () {
  1207. this.updateTable();
  1208. this.s.updating = true;
  1209. this.s.dt.draw();
  1210. this.s.updating = false;
  1211. };
  1212. /**
  1213. * Fill the array with the values that are currently being displayed in the table
  1214. *
  1215. * @param last boolean to indicate whether this was the last pane a selection was made in
  1216. */
  1217. SearchPane.prototype._populatePane = function (last) {
  1218. if (last === void 0) { last = false; }
  1219. var table = this.s.dt;
  1220. this.s.rowData.arrayFilter = [];
  1221. this.s.rowData.bins = {};
  1222. var settings = this.s.dt.settings()[0];
  1223. // If cascadePanes or viewTotal are active it is necessary to get the data which is currently
  1224. // being displayed for their functionality.
  1225. // Also make sure that this was not the last pane to have a selection made
  1226. if (!this.s.dt.page.info().serverSide) {
  1227. var indexArray = (this.c.cascadePanes || this.c.viewTotal) && (!this.s.clearing && !last) ?
  1228. table.rows({ search: 'applied' }).indexes() :
  1229. table.rows().indexes();
  1230. for (var _i = 0, _a = indexArray.toArray(); _i < _a.length; _i++) {
  1231. var index = _a[_i];
  1232. this._populatePaneArray(index, this.s.rowData.arrayFilter, settings);
  1233. }
  1234. }
  1235. };
  1236. /**
  1237. * Populates an array with all of the data for the table
  1238. *
  1239. * @param rowIdx The current row index to be compared
  1240. * @param arrayFilter The array that is to be populated with row Details
  1241. * @param bins The bins object that is to be populated with the row counts
  1242. */
  1243. SearchPane.prototype._populatePaneArray = function (rowIdx, arrayFilter, settings, bins) {
  1244. if (bins === void 0) { bins = this.s.rowData.bins; }
  1245. var colOpts = this.s.colOpts;
  1246. // Retrieve the rendered data from the cell using the fnGetCellData function
  1247. // rather than the cell().render API method for optimisation
  1248. if (typeof colOpts.orthogonal === 'string') {
  1249. var rendered = settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal);
  1250. this.s.rowData.filterMap.set(rowIdx, rendered);
  1251. this._addOption(rendered, rendered, rendered, rendered, arrayFilter, bins);
  1252. }
  1253. else {
  1254. var filter = settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.search);
  1255. // Null and empty string are to be considered the same value
  1256. if (filter === null) {
  1257. filter = '';
  1258. }
  1259. if (typeof filter === 'string') {
  1260. filter = filter.replace(/<[^>]*>/g, '');
  1261. }
  1262. this.s.rowData.filterMap.set(rowIdx, filter);
  1263. if (!bins[filter]) {
  1264. bins[filter] = 1;
  1265. this._addOption(filter, settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.display), settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.sort), settings.oApi._fnGetCellData(settings, rowIdx, this.s.index, colOpts.orthogonal.type), arrayFilter, bins);
  1266. this.s.rowData.totalOptions++;
  1267. }
  1268. else {
  1269. bins[filter]++;
  1270. this.s.rowData.totalOptions++;
  1271. return;
  1272. }
  1273. }
  1274. };
  1275. /**
  1276. * Reloads all of the previous selects into the panes
  1277. *
  1278. * @param loadedFilter The loaded filters from a previous state
  1279. */
  1280. SearchPane.prototype._reloadSelect = function (loadedFilter) {
  1281. // If the state was not saved don't selected any
  1282. if (loadedFilter === undefined) {
  1283. return;
  1284. }
  1285. var idx;
  1286. // For each pane, check that the loadedFilter list exists and is not null,
  1287. // find the id of each search item and set it to be selected.
  1288. for (var i = 0; i < loadedFilter.searchPanes.panes.length; i++) {
  1289. if (loadedFilter.searchPanes.panes[i].id === this.s.index) {
  1290. idx = i;
  1291. break;
  1292. }
  1293. }
  1294. if (idx !== undefined) {
  1295. var table = this.s.dtPane;
  1296. var rows = table.rows({ order: 'index' }).data().map(function (item) { return item.filter !== null ?
  1297. item.filter.toString() :
  1298. null; }).toArray();
  1299. for (var _i = 0, _a = loadedFilter.searchPanes.panes[idx].selected; _i < _a.length; _i++) {
  1300. var filter = _a[_i];
  1301. var id = -1;
  1302. if (filter !== null) {
  1303. id = rows.indexOf(filter.toString());
  1304. }
  1305. if (id > -1) {
  1306. this.s.serverSelecting = true;
  1307. table.row(id).select();
  1308. this.s.serverSelecting = false;
  1309. }
  1310. }
  1311. }
  1312. };
  1313. /**
  1314. * This method decides whether a row should contribute to the pane or not
  1315. *
  1316. * @param filter the value that the row is to be filtered on
  1317. * @param dataIndex the row index
  1318. */
  1319. SearchPane.prototype._search = function (filter, dataIndex) {
  1320. var colOpts = this.s.colOpts;
  1321. var table = this.s.dt;
  1322. // For each item selected in the pane, check if it is available in the cell
  1323. for (var _i = 0, _a = this.selections; _i < _a.length; _i++) {
  1324. var colSelect = _a[_i];
  1325. if (typeof colSelect.filter === 'string' && typeof filter === 'string') {
  1326. // The filter value will not have the &amp; in place but a &,
  1327. // so we need to do a replace to make sure that they will match
  1328. colSelect.filter = colSelect.filter
  1329. .replace(/&amp;/g, '&')
  1330. .replace(/&lt;/g, '<')
  1331. .replace(/&gt;/g, '>')
  1332. .replace(/&quot;/g, '"');
  1333. }
  1334. // if the filter is an array then is the column present in it
  1335. if (Array.isArray(filter)) {
  1336. if (filter.indexOf(colSelect.filter) !== -1) {
  1337. return true;
  1338. }
  1339. }
  1340. // if the filter is a function then does it meet the criteria of that function or not
  1341. else if (typeof colSelect.filter === 'function') {
  1342. if (colSelect.filter.call(table, table.row(dataIndex).data(), dataIndex)) {
  1343. if (colOpts.combiner === 'or') {
  1344. return true;
  1345. }
  1346. }
  1347. // If the combiner is an "and" then we need to check against all possible selections
  1348. // so if it fails here then the and is not met and return false
  1349. else if (colOpts.combiner === 'and') {
  1350. return false;
  1351. }
  1352. }
  1353. // otherwise if the two filter values are equal then return true
  1354. else if ((filter === colSelect.filter) ||
  1355. // Loose type checking incase number type in column comparing to a string
  1356. // eslint-disable-next-line eqeqeq
  1357. (!(typeof filter === 'string' && filter.length === 0) && filter == colSelect.filter) ||
  1358. (colSelect.filter === null && typeof filter === 'string' && filter === '')) {
  1359. return true;
  1360. }
  1361. }
  1362. // If the combiner is an and then we need to check against all possible selections
  1363. // so return true here if so because it would have returned false earlier if it had failed
  1364. if (colOpts.combiner === 'and') {
  1365. return true;
  1366. }
  1367. // Otherwise it hasn't matched with anything by this point so it must be false
  1368. else {
  1369. return false;
  1370. }
  1371. };
  1372. /**
  1373. * Creates the contents of the searchCont div
  1374. *
  1375. * NOTE This is overridden when semantic ui styling in order to integrate the search button into the text box.
  1376. */
  1377. SearchPane.prototype._searchContSetup = function () {
  1378. if (this.c.controls && this.s.colOpts.controls) {
  1379. $(this.dom.searchButton).appendTo(this.dom.searchLabelCont);
  1380. }
  1381. if (!(this.c.dtOpts.searching === false ||
  1382. this.s.colOpts.dtOpts.searching === false ||
  1383. (this.customPaneSettings !== null &&
  1384. this.customPaneSettings.dtOpts !== undefined &&
  1385. this.customPaneSettings.dtOpts.searching !== undefined &&
  1386. !this.customPaneSettings.dtOpts.searching))) {
  1387. $(this.dom.searchLabelCont).appendTo(this.dom.searchCont);
  1388. }
  1389. };
  1390. /**
  1391. * Adds outline to the pane when a selection has been made
  1392. */
  1393. SearchPane.prototype._searchExtras = function () {
  1394. var updating = this.s.updating;
  1395. this.s.updating = true;
  1396. var filters = this.s.dtPane.rows({ selected: true }).data().pluck('filter').toArray();
  1397. var nullIndex = filters.indexOf(this.emptyMessage());
  1398. var container = $(this.s.dtPane.table().container());
  1399. // If null index is found then search for empty cells as a filter.
  1400. if (nullIndex > -1) {
  1401. filters[nullIndex] = '';
  1402. }
  1403. // If a filter has been applied then outline the respective pane, remove it when it no longer is.
  1404. if (filters.length > 0) {
  1405. container.addClass(this.classes.selected);
  1406. }
  1407. else if (filters.length === 0) {
  1408. container.removeClass(this.classes.selected);
  1409. }
  1410. this.s.updating = updating;
  1411. };
  1412. /**
  1413. * Finds the ratio of the number of different options in the table to the number of rows
  1414. *
  1415. * @param bins the number of different options in the table
  1416. * @param rowCount the total number of rows in the table
  1417. * @returns {number} returns the ratio
  1418. */
  1419. SearchPane.prototype._uniqueRatio = function (bins, rowCount) {
  1420. if (rowCount > 0 &&
  1421. ((this.s.rowData.totalOptions > 0 && !this.s.dt.page.info().serverSide) ||
  1422. (this.s.dt.page.info().serverSide && this.s.tableLength > 0))) {
  1423. return bins / this.s.rowData.totalOptions;
  1424. }
  1425. else {
  1426. return 1;
  1427. }
  1428. };
  1429. /**
  1430. * updates the options within the pane
  1431. *
  1432. * @param draw a flag to define whether this has been called due to a draw event or not
  1433. */
  1434. SearchPane.prototype._updateCommon = function (draw) {
  1435. if (draw === void 0) { draw = false; }
  1436. // Update the panes if doing a deselect. if doing a select then
  1437. // update all of the panes except for the one causing the change
  1438. if (!this.s.dt.page.info().serverSide &&
  1439. this.s.dtPane !== undefined &&
  1440. (!this.s.filteringActive || this.c.cascadePanes || draw === true) &&
  1441. (this.c.cascadePanes !== true || this.s.selectPresent !== true) &&
  1442. (!this.s.lastSelect || !this.s.lastCascade)) {
  1443. var colOpts = this.s.colOpts;
  1444. var selected = this.s.dtPane.rows({ selected: true }).data().toArray();
  1445. var scrollTop = $(this.s.dtPane.table().node()).parent()[0].scrollTop;
  1446. var rowData = this.s.rowData;
  1447. // Clear the pane in preparation for adding the updated search options
  1448. this.s.dtPane.clear();
  1449. // If it is not a custom pane
  1450. if (this.colExists) {
  1451. // Only run populatePane if the data has not been collected yet
  1452. if (rowData.arrayFilter.length === 0) {
  1453. this._populatePane(!this.s.filteringActive);
  1454. }
  1455. // If cascadePanes is active and the table has returned to its default state then
  1456. // there is a need to update certain parts ofthe rowData.
  1457. else if (this.c.cascadePanes &&
  1458. this.s.dt.rows().data().toArray().length ===
  1459. this.s.dt.rows({ search: 'applied' }).data().toArray().length) {
  1460. rowData.arrayFilter = rowData.arrayOriginal;
  1461. rowData.bins = rowData.binsOriginal;
  1462. }
  1463. // Otherwise if viewTotal or cascadePanes is active then the data from the table must be read.
  1464. else if (this.c.viewTotal || this.c.cascadePanes) {
  1465. this._populatePane(!this.s.filteringActive);
  1466. }
  1467. // If the viewTotal option is selected then find the totals for the table
  1468. if (this.c.viewTotal) {
  1469. this._detailsPane();
  1470. }
  1471. else {
  1472. rowData.binsTotal = rowData.bins;
  1473. }
  1474. if (this.c.viewTotal && !this.c.cascadePanes) {
  1475. rowData.arrayFilter = rowData.arrayTotals;
  1476. }
  1477. var _loop_1 = function (dataP) {
  1478. // If both view Total and cascadePanes have been selected and the count of the row
  1479. // is not 0 then add it to pane
  1480. // Do this also if the viewTotal option has been selected and cascadePanes has not
  1481. if (dataP && ((rowData.bins[dataP.filter] !== undefined &&
  1482. rowData.bins[dataP.filter] !== 0 && this_1.c.cascadePanes) ||
  1483. !this_1.c.cascadePanes ||
  1484. this_1.s.clearing)) {
  1485. var row = this_1.addRow(dataP.display, dataP.filter, !this_1.c.viewTotal ?
  1486. rowData.bins[dataP.filter] :
  1487. rowData.bins[dataP.filter] !== undefined ?
  1488. rowData.bins[dataP.filter] :
  1489. 0, this_1.c.viewTotal ?
  1490. String(rowData.binsTotal[dataP.filter]) :
  1491. rowData.bins[dataP.filter], dataP.sort, dataP.type);
  1492. // Find out if the filter was selected in the previous search,
  1493. // if so select it and remove from array.
  1494. var selectIndex = selected.findIndex(function (element) {
  1495. return element.filter === dataP.filter;
  1496. });
  1497. if (selectIndex !== -1) {
  1498. row.select();
  1499. selected.splice(selectIndex, 1);
  1500. }
  1501. }
  1502. };
  1503. var this_1 = this;
  1504. for (var _i = 0, _a = rowData.arrayFilter; _i < _a.length; _i++) {
  1505. var dataP = _a[_i];
  1506. _loop_1(dataP);
  1507. }
  1508. }
  1509. if ((colOpts.searchPanes !== undefined && colOpts.searchPanes.options !== undefined) ||
  1510. colOpts.options !== undefined ||
  1511. (this.customPaneSettings !== null && this.customPaneSettings.options !== undefined)) {
  1512. var rows = this._getComparisonRows();
  1513. var _loop_2 = function (row) {
  1514. var selectIndex = selected.findIndex(function (element) {
  1515. if (element.display === row.data().display) {
  1516. return true;
  1517. }
  1518. });
  1519. if (selectIndex !== -1) {
  1520. row.select();
  1521. selected.splice(selectIndex, 1);
  1522. }
  1523. };
  1524. for (var _b = 0, rows_1 = rows; _b < rows_1.length; _b++) {
  1525. var row = rows_1[_b];
  1526. _loop_2(row);
  1527. }
  1528. }
  1529. // Add search options which were previously selected but whos results are no
  1530. // longer present in the resulting data set.
  1531. for (var _c = 0, selected_1 = selected; _c < selected_1.length; _c++) {
  1532. var selectedEl = selected_1[_c];
  1533. var row = this.addRow(selectedEl.display, selectedEl.filter, 0, this.c.viewTotal
  1534. ? selectedEl.total
  1535. : 0, selectedEl.display, selectedEl.display);
  1536. this.s.updating = true;
  1537. row.select();
  1538. this.s.updating = false;
  1539. }
  1540. this.s.dtPane.draw();
  1541. this.s.dtPane.table().node().parentNode.scrollTop = scrollTop;
  1542. }
  1543. };
  1544. SearchPane.version = '1.3.0';
  1545. SearchPane.classes = {
  1546. buttonGroup: 'dtsp-buttonGroup',
  1547. buttonSub: 'dtsp-buttonSub',
  1548. clear: 'dtsp-clear',
  1549. clearAll: 'dtsp-clearAll',
  1550. clearButton: 'clearButton',
  1551. container: 'dtsp-searchPane',
  1552. countButton: 'dtsp-countButton',
  1553. disabledButton: 'dtsp-disabledButton',
  1554. hidden: 'dtsp-hidden',
  1555. hide: 'dtsp-hide',
  1556. layout: 'dtsp-',
  1557. name: 'dtsp-name',
  1558. nameButton: 'dtsp-nameButton',
  1559. nameCont: 'dtsp-nameCont',
  1560. narrow: 'dtsp-narrow',
  1561. paneButton: 'dtsp-paneButton',
  1562. paneInputButton: 'dtsp-paneInputButton',
  1563. pill: 'dtsp-pill',
  1564. search: 'dtsp-search',
  1565. searchCont: 'dtsp-searchCont',
  1566. searchIcon: 'dtsp-searchIcon',
  1567. searchLabelCont: 'dtsp-searchButtonCont',
  1568. selected: 'dtsp-selected',
  1569. smallGap: 'dtsp-smallGap',
  1570. subRow1: 'dtsp-subRow1',
  1571. subRow2: 'dtsp-subRow2',
  1572. subRowsContainer: 'dtsp-subRowsContainer',
  1573. title: 'dtsp-title',
  1574. topRow: 'dtsp-topRow'
  1575. };
  1576. // Define SearchPanes default options
  1577. SearchPane.defaults = {
  1578. cascadePanes: false,
  1579. clear: true,
  1580. combiner: 'or',
  1581. container: function (dt) {
  1582. return dt.table().container();
  1583. },
  1584. controls: true,
  1585. dtOpts: {},
  1586. emptyMessage: null,
  1587. hideCount: false,
  1588. i18n: {
  1589. clearPane: '&times;',
  1590. count: '{total}',
  1591. countFiltered: '{shown} ({total})',
  1592. emptyMessage: '<em>No data</em>'
  1593. },
  1594. layout: 'auto',
  1595. name: undefined,
  1596. orderable: true,
  1597. orthogonal: {
  1598. display: 'display',
  1599. filter: 'filter',
  1600. hideCount: false,
  1601. search: 'filter',
  1602. show: undefined,
  1603. sort: 'sort',
  1604. threshold: 0.6,
  1605. type: 'type',
  1606. viewCount: true
  1607. },
  1608. preSelect: [],
  1609. threshold: 0.6,
  1610. viewCount: true,
  1611. viewTotal: false
  1612. };
  1613. return SearchPane;
  1614. }());
  1615. var $$1;
  1616. var dataTable$1;
  1617. function setJQuery$1(jq) {
  1618. $$1 = jq;
  1619. dataTable$1 = jq.fn.dataTable;
  1620. }
  1621. var SearchPanes = /** @class */ (function () {
  1622. function SearchPanes(paneSettings, opts, fromInit) {
  1623. var _this = this;
  1624. if (fromInit === void 0) { fromInit = false; }
  1625. this.regenerating = false;
  1626. // Check that the required version of DataTables is included
  1627. if (!dataTable$1 || !dataTable$1.versionCheck || !dataTable$1.versionCheck('1.10.0')) {
  1628. throw new Error('SearchPane requires DataTables 1.10 or newer');
  1629. }
  1630. // Check that Select is included
  1631. if (!dataTable$1.select) {
  1632. throw new Error('SearchPane requires Select');
  1633. }
  1634. var table = new dataTable$1.Api(paneSettings);
  1635. this.classes = $$1.extend(true, {}, SearchPanes.classes);
  1636. // Get options from user
  1637. this.c = $$1.extend(true, {}, SearchPanes.defaults, opts);
  1638. // Add extra elements to DOM object including clear
  1639. this.dom = {
  1640. clearAll: $$1('<button type="button">Clear All</button>').addClass(this.classes.clearAll),
  1641. container: $$1('<div/>').addClass(this.classes.panes).text(table.i18n('searchPanes.loadMessage', this.c.i18n.loadMessage)),
  1642. emptyMessage: $$1('<div/>').addClass(this.classes.emptyMessage),
  1643. options: $$1('<div/>').addClass(this.classes.container),
  1644. panes: $$1('<div/>').addClass(this.classes.container),
  1645. title: $$1('<div/>').addClass(this.classes.title),
  1646. titleRow: $$1('<div/>').addClass(this.classes.titleRow),
  1647. wrapper: $$1('<div/>')
  1648. };
  1649. this.s = {
  1650. colOpts: [],
  1651. dt: table,
  1652. filterCount: 0,
  1653. filterPane: -1,
  1654. page: 0,
  1655. panes: [],
  1656. selectionList: [],
  1657. serverData: {},
  1658. stateRead: false,
  1659. updating: false
  1660. };
  1661. if (table.settings()[0]._searchPanes !== undefined) {
  1662. return;
  1663. }
  1664. this._getState();
  1665. if (this.s.dt.page.info().serverSide) {
  1666. table.on('preXhr.dt', function (e, settings, data) {
  1667. if (data.searchPanes === undefined) {
  1668. data.searchPanes = {};
  1669. }
  1670. if (data.searchPanes_null === undefined) {
  1671. data.searchPanes_null = {};
  1672. }
  1673. for (var _i = 0, _a = _this.s.selectionList; _i < _a.length; _i++) {
  1674. var selection = _a[_i];
  1675. var src = _this.s.dt.column(selection.index).dataSrc();
  1676. if (data.searchPanes[src] === undefined) {
  1677. data.searchPanes[src] = {};
  1678. }
  1679. if (data.searchPanes_null[src] === undefined) {
  1680. data.searchPanes_null[src] = {};
  1681. }
  1682. for (var i = 0; i < selection.rows.length; i++) {
  1683. data.searchPanes[src][i] = selection.rows[i].filter;
  1684. if (data.searchPanes[src][i] === null) {
  1685. data.searchPanes_null[src][i] = true;
  1686. }
  1687. }
  1688. }
  1689. });
  1690. }
  1691. // We are using the xhr event to rebuild the panes if required due to viewTotal being enabled
  1692. // If viewTotal is not enabled then we simply update the data from the server
  1693. table.on('xhr', function (e, settings, json, xhr) {
  1694. if (json && json.searchPanes && json.searchPanes.options) {
  1695. _this.s.serverData = json;
  1696. _this.s.serverData.tableLength = json.recordsTotal;
  1697. _this._serverTotals();
  1698. }
  1699. });
  1700. table.settings()[0]._searchPanes = this;
  1701. this.dom.clearAll.text(table.i18n('searchPanes.clearMessage', this.c.i18n.clearMessage));
  1702. if (this.s.dt.settings()[0]._bInitComplete || fromInit) {
  1703. this._paneDeclare(table, paneSettings, opts);
  1704. }
  1705. else {
  1706. table.one('preInit.dt', function (settings) {
  1707. _this._paneDeclare(table, paneSettings, opts);
  1708. });
  1709. }
  1710. return this;
  1711. }
  1712. /**
  1713. * Clear the selections of all of the panes
  1714. */
  1715. SearchPanes.prototype.clearSelections = function () {
  1716. // Load in all of the searchBoxes in the documents
  1717. var searches = this.dom.container.find('.' + this.classes.search.replace(/\s+/g, '.'));
  1718. // For each searchBox set the input text to be empty and then trigger
  1719. // an input on them so that they no longer filter the panes
  1720. searches.each(function () {
  1721. $$1(this).val('');
  1722. $$1(this).trigger('input');
  1723. });
  1724. var returnArray = [];
  1725. // For every pane, clear the selections in the pane
  1726. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  1727. var pane = _a[_i];
  1728. if (pane.s.dtPane !== undefined) {
  1729. returnArray.push(pane.clearPane());
  1730. }
  1731. }
  1732. return returnArray;
  1733. };
  1734. /**
  1735. * returns the container node for the searchPanes
  1736. */
  1737. SearchPanes.prototype.getNode = function () {
  1738. return this.dom.container;
  1739. };
  1740. /**
  1741. * rebuilds all of the panes
  1742. */
  1743. SearchPanes.prototype.rebuild = function (targetIdx, maintainSelection) {
  1744. if (targetIdx === void 0) { targetIdx = false; }
  1745. if (maintainSelection === void 0) { maintainSelection = false; }
  1746. $$1(this.dom.emptyMessage).remove();
  1747. // As a rebuild from scratch is required, empty the searchpanes container.
  1748. var returnArray = [];
  1749. // Rebuild each pane individually, if a specific pane has been selected then only rebuild that one
  1750. if (targetIdx === false) {
  1751. $$1(this.dom.panes).empty();
  1752. }
  1753. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  1754. var pane = _a[_i];
  1755. if (targetIdx !== false && pane.s.index !== targetIdx) {
  1756. continue;
  1757. }
  1758. pane.clearData();
  1759. returnArray.push(
  1760. // Pass a boolean to say whether this is the last choice made for maintaining selections when rebuilding
  1761. pane.rebuildPane(this.s.selectionList[this.s.selectionList.length - 1] !== undefined ?
  1762. pane.s.index === this.s.selectionList[this.s.selectionList.length - 1].index :
  1763. false, this.s.dt.page.info().serverSide ?
  1764. this.s.serverData :
  1765. undefined, null, maintainSelection));
  1766. $$1(this.dom.panes).append(pane.dom.container);
  1767. }
  1768. if (this.c.cascadePanes || this.c.viewTotal) {
  1769. this.redrawPanes(true);
  1770. }
  1771. else {
  1772. this._updateSelection();
  1773. }
  1774. // Attach panes, clear buttons, and title bar to the document
  1775. this._updateFilterCount();
  1776. this._attachPaneContainer();
  1777. this.s.dt.draw();
  1778. // Resize the panes incase there has been a change
  1779. this.resizePanes();
  1780. // If a single pane has been rebuilt then return only that pane
  1781. if (returnArray.length === 1) {
  1782. return returnArray[0];
  1783. }
  1784. // Otherwise return all of the panes that have been rebuilt
  1785. else {
  1786. return returnArray;
  1787. }
  1788. };
  1789. /**
  1790. * Redraws all of the panes
  1791. */
  1792. SearchPanes.prototype.redrawPanes = function (rebuild) {
  1793. if (rebuild === void 0) { rebuild = false; }
  1794. var table = this.s.dt;
  1795. // Only do this if the redraw isn't being triggered by the panes updating themselves
  1796. if (!this.s.updating && !this.s.dt.page.info().serverSide) {
  1797. var filterActive = true;
  1798. var filterPane = this.s.filterPane;
  1799. var selectTotal = null;
  1800. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  1801. var pane = _a[_i];
  1802. if (pane.s.dtPane !== undefined) {
  1803. selectTotal += pane.s.dtPane.rows({ selected: true }).data().toArray().length;
  1804. }
  1805. }
  1806. // If the number of rows currently visible is equal to the number of rows in the table
  1807. // then there can't be any filtering taking place
  1808. if (selectTotal === 0 &&
  1809. table.rows({ search: 'applied' }).data().toArray().length === table.rows().data().toArray().length) {
  1810. filterActive = false;
  1811. }
  1812. // Otherwise if viewTotal is active then it is necessary to determine which panes a select is present in.
  1813. // If there is only one pane with a selection present then it should not show the filtered message as
  1814. // more selections may be made in that pane.
  1815. else if (this.c.viewTotal) {
  1816. for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
  1817. var pane = _c[_b];
  1818. if (pane.s.dtPane !== undefined) {
  1819. var selectLength = pane.s.dtPane.rows({ selected: true }).data().toArray().length;
  1820. if (selectLength === 0) {
  1821. for (var _d = 0, _e = this.s.selectionList; _d < _e.length; _d++) {
  1822. var selection = _e[_d];
  1823. if (selection.index === pane.s.index && selection.rows.length !== 0) {
  1824. selectLength = selection.rows.length;
  1825. }
  1826. }
  1827. }
  1828. // If filterPane === -1 then a pane with a selection has not been found yet,
  1829. // so set filterPane to that panes index
  1830. if (selectLength > 0 && filterPane === -1) {
  1831. filterPane = pane.s.index;
  1832. }
  1833. // Then if another pane is found with a selection then set filterPane to null to
  1834. // show that multiple panes have selections present
  1835. else if (selectLength > 0) {
  1836. filterPane = null;
  1837. }
  1838. }
  1839. }
  1840. // If the searchbox is in place and filtering is applied then need to cascade down anyway
  1841. if (selectTotal === 0) {
  1842. filterPane = null;
  1843. }
  1844. }
  1845. var deselectIdx = void 0;
  1846. var newSelectionList = [];
  1847. // Don't run this if it is due to the panes regenerating
  1848. if (!this.regenerating) {
  1849. for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
  1850. var pane = _g[_f];
  1851. // Identify the pane where a selection or deselection has been made and add it to the list.
  1852. if (pane.s.selectPresent) {
  1853. this.s.selectionList.push({
  1854. index: pane.s.index,
  1855. protect: false,
  1856. rows: pane.s.dtPane.rows({ selected: true }).data().toArray()
  1857. });
  1858. table.state.save();
  1859. break;
  1860. }
  1861. else if (pane.s.deselect) {
  1862. deselectIdx = pane.s.index;
  1863. var selectedData = pane.s.dtPane.rows({ selected: true }).data().toArray();
  1864. if (selectedData.length > 0) {
  1865. this.s.selectionList.push({
  1866. index: pane.s.index,
  1867. protect: true,
  1868. rows: selectedData
  1869. });
  1870. }
  1871. }
  1872. }
  1873. if (this.s.selectionList.length > 0) {
  1874. var last = this.s.selectionList[this.s.selectionList.length - 1].index;
  1875. for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
  1876. var pane = _j[_h];
  1877. pane.s.lastSelect = (pane.s.index === last);
  1878. }
  1879. }
  1880. // Remove selections from the list from the pane where a deselect has taken place
  1881. for (var i = 0; i < this.s.selectionList.length; i++) {
  1882. if (this.s.selectionList[i].index !== deselectIdx || this.s.selectionList[i].protect === true) {
  1883. var further = false;
  1884. // Find out if this selection is the last one in the list for that pane
  1885. for (var j = i + 1; j < this.s.selectionList.length; j++) {
  1886. if (this.s.selectionList[j].index === this.s.selectionList[i].index) {
  1887. further = true;
  1888. }
  1889. }
  1890. // If there are no selections for this pane in the list then just push this one
  1891. if (!further) {
  1892. newSelectionList.push(this.s.selectionList[i]);
  1893. this.s.selectionList[i].protect = false;
  1894. }
  1895. }
  1896. }
  1897. var solePane = -1;
  1898. if (newSelectionList.length === 1 && selectTotal !== null && selectTotal !== 0) {
  1899. solePane = newSelectionList[0].index;
  1900. }
  1901. // Update all of the panes to reflect the current state of the filters
  1902. for (var _k = 0, _l = this.s.panes; _k < _l.length; _k++) {
  1903. var pane = _l[_k];
  1904. if (pane.s.dtPane !== undefined) {
  1905. var tempFilter = true;
  1906. pane.s.filteringActive = true;
  1907. if ((filterPane !== -1 && filterPane !== null && filterPane === pane.s.index) ||
  1908. filterActive === false ||
  1909. pane.s.index === solePane) {
  1910. tempFilter = false;
  1911. pane.s.filteringActive = false;
  1912. }
  1913. pane.updatePane(!tempFilter ? false : filterActive);
  1914. }
  1915. }
  1916. // Update the label that shows how many filters are in place
  1917. this._updateFilterCount();
  1918. // If the length of the selections are different then some of them have been
  1919. // removed and a deselect has occured
  1920. if (newSelectionList.length > 0 && (newSelectionList.length < this.s.selectionList.length || rebuild)) {
  1921. this._cascadeRegen(newSelectionList, selectTotal);
  1922. var last = newSelectionList[newSelectionList.length - 1].index;
  1923. for (var _m = 0, _o = this.s.panes; _m < _o.length; _m++) {
  1924. var pane = _o[_m];
  1925. pane.s.lastSelect = (pane.s.index === last);
  1926. }
  1927. }
  1928. else if (newSelectionList.length > 0) {
  1929. // Update all of the other panes as you would just making a normal selection
  1930. for (var _p = 0, _q = this.s.panes; _p < _q.length; _p++) {
  1931. var paneUpdate = _q[_p];
  1932. if (paneUpdate.s.dtPane !== undefined) {
  1933. var tempFilter = true;
  1934. paneUpdate.s.filteringActive = true;
  1935. if ((filterPane !== -1 && filterPane !== null && filterPane === paneUpdate.s.index) ||
  1936. filterActive === false ||
  1937. paneUpdate.s.index === solePane) {
  1938. tempFilter = false;
  1939. paneUpdate.s.filteringActive = false;
  1940. }
  1941. paneUpdate.updatePane(!tempFilter ? tempFilter : filterActive);
  1942. }
  1943. }
  1944. }
  1945. }
  1946. else {
  1947. var solePane = -1;
  1948. if (newSelectionList.length === 1 && selectTotal !== null && selectTotal !== 0) {
  1949. solePane = newSelectionList[0].index;
  1950. }
  1951. for (var _r = 0, _s = this.s.panes; _r < _s.length; _r++) {
  1952. var pane = _s[_r];
  1953. if (pane.s.dtPane !== undefined) {
  1954. var tempFilter = true;
  1955. pane.s.filteringActive = true;
  1956. if ((filterPane !== -1 && filterPane !== null && filterPane === pane.s.index) ||
  1957. filterActive === false ||
  1958. pane.s.index === solePane) {
  1959. tempFilter = false;
  1960. pane.s.filteringActive = false;
  1961. }
  1962. pane.updatePane(!tempFilter ? tempFilter : filterActive);
  1963. }
  1964. }
  1965. // Update the label that shows how many filters are in place
  1966. this._updateFilterCount();
  1967. }
  1968. if (!filterActive || selectTotal === 0) {
  1969. this.s.selectionList = [];
  1970. }
  1971. }
  1972. };
  1973. /**
  1974. * Resizes all of the panes
  1975. */
  1976. SearchPanes.prototype.resizePanes = function () {
  1977. if (this.c.layout === 'auto') {
  1978. var contWidth = $$1(this.s.dt.searchPanes.container()).width();
  1979. var target = Math.floor(contWidth / 260.0); // The neatest number of panes per row
  1980. var highest = 1;
  1981. var highestmod = 0;
  1982. var dispIndex = [];
  1983. // Get the indexes of all of the displayed panes
  1984. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  1985. var pane = _a[_i];
  1986. if (pane.s.displayed) {
  1987. dispIndex.push(pane.s.index);
  1988. }
  1989. }
  1990. var displayCount = dispIndex.length;
  1991. // If the neatest number is the number we have then use this.
  1992. if (target === displayCount) {
  1993. highest = target;
  1994. }
  1995. else {
  1996. // Go from the target down and find the value with the most panes left over, this will be the best fit
  1997. for (var ppr = target; ppr > 1; ppr--) {
  1998. var rem = displayCount % ppr;
  1999. if (rem === 0) {
  2000. highest = ppr;
  2001. highestmod = 0;
  2002. break;
  2003. }
  2004. // If there are more left over at this amount of panes per row (ppr)
  2005. // then it fits better so new values
  2006. else if (rem > highestmod) {
  2007. highest = ppr;
  2008. highestmod = rem;
  2009. }
  2010. }
  2011. }
  2012. // If there is a perfect fit then none are to be wider
  2013. var widerIndexes = highestmod !== 0 ? dispIndex.slice(dispIndex.length - highestmod, dispIndex.length) : [];
  2014. for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
  2015. var pane = _c[_b];
  2016. // Resize the pane with the new layout
  2017. if (pane.s.displayed) {
  2018. var layout = 'columns-' + (widerIndexes.indexOf(pane.s.index) === -1 ? highest : highestmod);
  2019. pane.resize(layout);
  2020. }
  2021. }
  2022. }
  2023. else {
  2024. for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
  2025. var pane = _e[_d];
  2026. pane.adjustTopRow();
  2027. }
  2028. }
  2029. return this;
  2030. };
  2031. /**
  2032. * Attach the panes, buttons and title to the document
  2033. */
  2034. SearchPanes.prototype._attach = function () {
  2035. var _this = this;
  2036. $$1(this.dom.container).removeClass(this.classes.hide);
  2037. $$1(this.dom.titleRow).removeClass(this.classes.hide);
  2038. $$1(this.dom.titleRow).remove();
  2039. $$1(this.dom.title).appendTo(this.dom.titleRow);
  2040. // If the clear button is permitted attach it
  2041. if (this.c.clear) {
  2042. $$1(this.dom.clearAll).appendTo(this.dom.titleRow);
  2043. $$1(this.dom.clearAll).on('click.dtsps', function () {
  2044. _this.clearSelections();
  2045. });
  2046. }
  2047. $$1(this.dom.titleRow).appendTo(this.dom.container);
  2048. // Attach the container for each individual pane to the overall container
  2049. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2050. var pane = _a[_i];
  2051. $$1(pane.dom.container).appendTo(this.dom.panes);
  2052. }
  2053. // Attach everything to the document
  2054. $$1(this.dom.panes).appendTo(this.dom.container);
  2055. if ($$1('div.' + this.classes.container).length === 0) {
  2056. $$1(this.dom.container).prependTo(this.s.dt);
  2057. }
  2058. return this.dom.container;
  2059. };
  2060. /**
  2061. * Attach the top row containing the filter count and clear all button
  2062. */
  2063. SearchPanes.prototype._attachExtras = function () {
  2064. $$1(this.dom.container).removeClass(this.classes.hide);
  2065. $$1(this.dom.titleRow).removeClass(this.classes.hide);
  2066. $$1(this.dom.titleRow).remove();
  2067. $$1(this.dom.title).appendTo(this.dom.titleRow);
  2068. // If the clear button is permitted attach it
  2069. if (this.c.clear) {
  2070. $$1(this.dom.clearAll).appendTo(this.dom.titleRow);
  2071. }
  2072. $$1(this.dom.titleRow).appendTo(this.dom.container);
  2073. return this.dom.container;
  2074. };
  2075. /**
  2076. * If there are no panes to display then this method is called to either
  2077. * display a message in their place or hide them completely.
  2078. */
  2079. SearchPanes.prototype._attachMessage = function () {
  2080. // Create a message to display on the screen
  2081. var message;
  2082. try {
  2083. message = this.s.dt.i18n('searchPanes.emptyPanes', this.c.i18n.emptyPanes);
  2084. }
  2085. catch (error) {
  2086. message = null;
  2087. }
  2088. // If the message is an empty string then searchPanes.emptyPanes is undefined,
  2089. // therefore the pane container should be removed from the display
  2090. if (message === null) {
  2091. $$1(this.dom.container).addClass(this.classes.hide);
  2092. $$1(this.dom.titleRow).removeClass(this.classes.hide);
  2093. return;
  2094. }
  2095. else {
  2096. $$1(this.dom.container).removeClass(this.classes.hide);
  2097. $$1(this.dom.titleRow).addClass(this.classes.hide);
  2098. }
  2099. // Otherwise display the message
  2100. $$1(this.dom.emptyMessage).text(message);
  2101. this.dom.emptyMessage.appendTo(this.dom.container);
  2102. return this.dom.container;
  2103. };
  2104. /**
  2105. * Attaches the panes to the document and displays a message or hides if there are none
  2106. */
  2107. SearchPanes.prototype._attachPaneContainer = function () {
  2108. // If a pane is to be displayed then attach the normal pane output
  2109. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2110. var pane = _a[_i];
  2111. if (pane.s.displayed === true) {
  2112. return this._attach();
  2113. }
  2114. }
  2115. // Otherwise attach the custom message or remove the container from the display
  2116. return this._attachMessage();
  2117. };
  2118. /**
  2119. * Prepares the panes for selections to be made when cascade is active and a deselect has occured
  2120. *
  2121. * @param newSelectionList the list of selections which are to be made
  2122. */
  2123. SearchPanes.prototype._cascadeRegen = function (newSelectionList, selectTotal) {
  2124. // Set this to true so that the actions taken do not cause this to run until it is finished
  2125. this.regenerating = true;
  2126. // If only one pane has been selected then take note of its index
  2127. var solePane = -1;
  2128. if (newSelectionList.length === 1 && selectTotal !== null && selectTotal !== 0) {
  2129. solePane = newSelectionList[0].index;
  2130. }
  2131. // Let the pane know that a cascadeRegen is taking place to avoid unexpected behaviour
  2132. // and clear all of the previous selections in the pane
  2133. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2134. var pane = _a[_i];
  2135. pane.setCascadeRegen(true);
  2136. pane.setClear(true);
  2137. // If this is the same as the pane with the only selection then pass it as a parameter into clearPane
  2138. if ((pane.s.dtPane !== undefined && pane.s.index === solePane) || pane.s.dtPane !== undefined) {
  2139. pane.clearPane();
  2140. }
  2141. pane.setClear(false);
  2142. }
  2143. // Rebin panes
  2144. this.s.dt.draw();
  2145. // While all of the selections have been removed, check the table lengths
  2146. // If they are different, another filter is in place and we need to force viewTotal to be used
  2147. var noSelectionsTableLength = this.s.dt.rows({ search: 'applied' }).data().toArray().length;
  2148. var tableLength = this.s.dt.rows().data().toArray().length;
  2149. if (tableLength !== noSelectionsTableLength) {
  2150. for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
  2151. var pane = _c[_b];
  2152. pane.s.forceViewTotal = true;
  2153. }
  2154. }
  2155. for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
  2156. var pane = _e[_d];
  2157. pane.updatePane(true);
  2158. }
  2159. // Remake Selections
  2160. this._makeCascadeSelections(newSelectionList);
  2161. // Set the selection list property to be the list without the selections from the deselect pane
  2162. this.s.selectionList = newSelectionList;
  2163. // The regeneration of selections is over so set it back to false
  2164. for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
  2165. var pane = _g[_f];
  2166. pane.setCascadeRegen(false);
  2167. }
  2168. this.regenerating = false;
  2169. // ViewTotal has already been forced at this point so can cancel that for future
  2170. if (tableLength !== noSelectionsTableLength) {
  2171. for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
  2172. var pane = _j[_h];
  2173. pane.s.forceViewTotal = false;
  2174. }
  2175. }
  2176. };
  2177. /**
  2178. * Attaches the message to the document but does not add any panes
  2179. */
  2180. SearchPanes.prototype._checkMessage = function () {
  2181. // If a pane is to be displayed then attach the normal pane output
  2182. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2183. var pane = _a[_i];
  2184. if (pane.s.displayed === true) {
  2185. // Ensure that the empty message is removed if a pane is displayed
  2186. $$1(this.dom.emptyMessage).remove();
  2187. $$1(this.dom.titleRow).removeClass(this.classes.hide);
  2188. return;
  2189. }
  2190. }
  2191. // Otherwise attach the custom message or remove the container from the display
  2192. return this._attachMessage();
  2193. };
  2194. /**
  2195. * Gets the selection list from the previous state and stores it in the selectionList Property
  2196. */
  2197. SearchPanes.prototype._getState = function () {
  2198. var loadedFilter = this.s.dt.state.loaded();
  2199. if (loadedFilter && loadedFilter.searchPanes && loadedFilter.searchPanes.selectionList !== undefined) {
  2200. this.s.selectionList = loadedFilter.searchPanes.selectionList;
  2201. }
  2202. };
  2203. /**
  2204. * Makes all of the selections when cascade is active
  2205. *
  2206. * @param newSelectionList the list of selections to be made, in the order they were originally selected
  2207. */
  2208. SearchPanes.prototype._makeCascadeSelections = function (newSelectionList) {
  2209. // make selections in the order they were made previously,
  2210. // excluding those from the pane where a deselect was made
  2211. for (var i = 0; i < newSelectionList.length; i++) {
  2212. var _loop_1 = function (pane) {
  2213. if (pane.s.index === newSelectionList[i].index && pane.s.dtPane !== undefined) {
  2214. // When regenerating the cascade selections we need this flag so that
  2215. // the panes are only ignored if it
  2216. // is the last selection and the pane for that selection
  2217. if (i === newSelectionList.length - 1) {
  2218. pane.s.lastCascade = true;
  2219. }
  2220. // if there are any selections currently in the pane then
  2221. // deselect them as we are about to make our new selections
  2222. if (pane.s.dtPane.rows({ selected: true }).data().toArray().length > 0 && pane.s.dtPane !== undefined) {
  2223. pane.setClear(true);
  2224. pane.clearPane();
  2225. pane.setClear(false);
  2226. }
  2227. var _loop_2 = function (row) {
  2228. var found = false;
  2229. pane.s.dtPane.rows().every(function (rowIdx) {
  2230. if (pane.s.dtPane.row(rowIdx).data() !== undefined &&
  2231. row !== undefined &&
  2232. pane.s.dtPane.row(rowIdx).data().filter === row.filter) {
  2233. found = true;
  2234. pane.s.dtPane.row(rowIdx).select();
  2235. }
  2236. });
  2237. if (!found) {
  2238. var newRow = pane.addRow(row.display, row.filter, 0, row.total, row.sort, row.type, row.className);
  2239. newRow.select();
  2240. }
  2241. };
  2242. // select every row in the pane that was selected previously
  2243. for (var _i = 0, _a = newSelectionList[i].rows; _i < _a.length; _i++) {
  2244. var row = _a[_i];
  2245. _loop_2(row);
  2246. }
  2247. pane.s.dtPane.draw();
  2248. // Update the label that shows how many filters are in place
  2249. this_1._updateFilterCount();
  2250. pane.s.lastCascade = false;
  2251. }
  2252. };
  2253. var this_1 = this;
  2254. // As the selections may have been made across the panes
  2255. // in a different order to the pane index we must identify
  2256. // which pane has the index of the selection. This is also important for colreorder etc
  2257. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2258. var pane = _a[_i];
  2259. _loop_1(pane);
  2260. }
  2261. }
  2262. // Make sure that the state is saved after all of these selections
  2263. this.s.dt.state.save();
  2264. };
  2265. /**
  2266. * Declares the instances of individual searchpanes dependant on the number of columns.
  2267. * It is necessary to run this once preInit has completed otherwise no panes will be
  2268. * created as the column count will be 0.
  2269. *
  2270. * @param table the DataTable api for the parent table
  2271. * @param paneSettings the settings passed into the constructor
  2272. * @param opts the options passed into the constructor
  2273. */
  2274. SearchPanes.prototype._paneDeclare = function (table, paneSettings, opts) {
  2275. var _this = this;
  2276. // Create Panes
  2277. table
  2278. .columns(this.c.columns.length > 0 ? this.c.columns : undefined)
  2279. .eq(0)
  2280. .each(function (idx) {
  2281. _this.s.panes.push(new SearchPane(paneSettings, opts, idx, _this.c.layout, _this.dom.panes));
  2282. });
  2283. // If there is any extra custom panes defined then create panes for them too
  2284. var rowLength = table.columns().eq(0).toArray().length;
  2285. var paneLength = this.c.panes.length;
  2286. for (var i = 0; i < paneLength; i++) {
  2287. var id = rowLength + i;
  2288. this.s.panes.push(new SearchPane(paneSettings, opts, id, this.c.layout, this.dom.panes, this.c.panes[i]));
  2289. }
  2290. // If a custom ordering is being used
  2291. if (this.c.order.length > 0) {
  2292. // Make a new Array of panes based upon the order
  2293. var newPanes = this.c.order.map(function (name, index, values) { return _this._findPane(name); });
  2294. // Remove the old panes from the dom
  2295. this.dom.panes.empty();
  2296. this.s.panes = newPanes;
  2297. // Append the panes in the correct order
  2298. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2299. var pane = _a[_i];
  2300. this.dom.panes.append(pane.dom.container);
  2301. }
  2302. }
  2303. // If this internal property is true then the DataTable has been initialised already
  2304. if (this.s.dt.settings()[0]._bInitComplete) {
  2305. this._startup(table);
  2306. }
  2307. else {
  2308. // Otherwise add the paneStartup function to the list of functions
  2309. // that are to be run when the table is initialised. This will garauntee that the
  2310. // panes are initialised before the init event and init Complete callback is fired
  2311. this.s.dt.settings()[0].aoInitComplete.push({ fn: function () {
  2312. _this._startup(table);
  2313. } });
  2314. }
  2315. };
  2316. /**
  2317. * Finds a pane based upon the name of that pane
  2318. *
  2319. * @param name string representing the name of the pane
  2320. * @returns SearchPane The pane which has that name
  2321. */
  2322. SearchPanes.prototype._findPane = function (name) {
  2323. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2324. var pane = _a[_i];
  2325. if (name === pane.s.name) {
  2326. return pane;
  2327. }
  2328. }
  2329. };
  2330. /**
  2331. * Works out which panes to update when data is recieved from the server and viewTotal is active
  2332. */
  2333. SearchPanes.prototype._serverTotals = function () {
  2334. var selectPresent = false;
  2335. var deselectPresent = false;
  2336. var table = this.s.dt;
  2337. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2338. var pane = _a[_i];
  2339. // Identify the pane where a selection or deselection has been made and add it to the list.
  2340. if (pane.s.selectPresent) {
  2341. this.s.selectionList.push({
  2342. index: pane.s.index,
  2343. protect: false,
  2344. rows: pane.s.dtPane.rows({ selected: true }).data().toArray()
  2345. });
  2346. table.state.save();
  2347. pane.s.selectPresent = false;
  2348. selectPresent = true;
  2349. break;
  2350. }
  2351. else if (pane.s.deselect) {
  2352. var selectedData = pane.s.dtPane.rows({ selected: true }).data().toArray();
  2353. if (selectedData.length > 0) {
  2354. this.s.selectionList.push({
  2355. index: pane.s.index,
  2356. protect: true,
  2357. rows: selectedData
  2358. });
  2359. }
  2360. selectPresent = true;
  2361. deselectPresent = true;
  2362. }
  2363. }
  2364. // Build an updated list based on any selections or deselections added
  2365. if (!selectPresent) {
  2366. this.s.selectionList = [];
  2367. }
  2368. else {
  2369. var newSelectionList = [];
  2370. for (var i = 0; i < this.s.selectionList.length; i++) {
  2371. var further = false;
  2372. // Find out if this selection is the last one in the list for that pane
  2373. for (var j = i + 1; j < this.s.selectionList.length; j++) {
  2374. if (this.s.selectionList[j].index === this.s.selectionList[i].index) {
  2375. further = true;
  2376. }
  2377. }
  2378. // If there are no selections for this pane in the list then just push this one
  2379. if (!further) {
  2380. var push = false;
  2381. for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
  2382. var pane = _c[_b];
  2383. if (pane.s.index === this.s.selectionList[i].index &&
  2384. pane.s.dtPane.rows({ selected: true }).data().toArray().length > 0) {
  2385. push = true;
  2386. }
  2387. }
  2388. if (push) {
  2389. newSelectionList.push(this.s.selectionList[i]);
  2390. }
  2391. }
  2392. }
  2393. this.s.selectionList = newSelectionList;
  2394. }
  2395. var initIdx = -1;
  2396. // If there has been a deselect and only one pane has a selection then update everything
  2397. if (deselectPresent && this.s.selectionList.length === 1) {
  2398. for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
  2399. var pane = _e[_d];
  2400. pane.s.lastSelect = false;
  2401. pane.s.deselect = false;
  2402. if (pane.s.dtPane !== undefined && pane.s.dtPane.rows({ selected: true }).data().toArray().length > 0) {
  2403. initIdx = pane.s.index;
  2404. }
  2405. }
  2406. }
  2407. // Otherwise if there are more 1 selections then find the last one and set it to not update that pane
  2408. else if (this.s.selectionList.length > 0) {
  2409. var last = this.s.selectionList[this.s.selectionList.length - 1].index;
  2410. for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
  2411. var pane = _g[_f];
  2412. pane.s.lastSelect = (pane.s.index === last);
  2413. pane.s.deselect = false;
  2414. }
  2415. }
  2416. // Otherwise if there are no selections then find where that took place and do not update to maintain scrolling
  2417. else if (this.s.selectionList.length === 0) {
  2418. for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
  2419. var pane = _j[_h];
  2420. // pane.s.lastSelect = (pane.s.deselect === true);
  2421. pane.s.lastSelect = false;
  2422. pane.s.deselect = false;
  2423. }
  2424. }
  2425. $$1(this.dom.panes).empty();
  2426. // Rebuild the desired panes
  2427. for (var _k = 0, _l = this.s.panes; _k < _l.length; _k++) {
  2428. var pane = _l[_k];
  2429. if (!pane.s.lastSelect) {
  2430. pane.rebuildPane(undefined, this.s.dt.page.info().serverSide ? this.s.serverData : undefined, pane.s.index === initIdx ? true : null, true);
  2431. }
  2432. else {
  2433. pane._setListeners();
  2434. }
  2435. // append all of the panes and enable select
  2436. $$1(this.dom.panes).append(pane.dom.container);
  2437. if (pane.s.dtPane !== undefined) {
  2438. $$1(pane.s.dtPane.table().node()).parent()[0].scrollTop = pane.s.scrollTop;
  2439. $$1.fn.dataTable.select.init(pane.s.dtPane);
  2440. }
  2441. }
  2442. this._updateSelection();
  2443. };
  2444. /**
  2445. * Initialises the tables previous/preset selections and initialises callbacks for events
  2446. *
  2447. * @param table the parent table for which the searchPanes are being created
  2448. */
  2449. SearchPanes.prototype._startup = function (table) {
  2450. var _this = this;
  2451. $$1(this.dom.container).text('');
  2452. // Attach clear button and title bar to the document
  2453. this._attachExtras();
  2454. $$1(this.dom.container).append(this.dom.panes);
  2455. $$1(this.dom.panes).empty();
  2456. var loadedFilter = this.s.dt.state.loaded();
  2457. if (this.c.viewTotal && !this.c.cascadePanes) {
  2458. if (loadedFilter !== null &&
  2459. loadedFilter !== undefined &&
  2460. loadedFilter.searchPanes !== undefined &&
  2461. loadedFilter.searchPanes.panes !== undefined) {
  2462. var filterActive = false;
  2463. for (var _i = 0, _a = loadedFilter.searchPanes.panes; _i < _a.length; _i++) {
  2464. var pane = _a[_i];
  2465. if (pane.selected.length > 0) {
  2466. filterActive = true;
  2467. break;
  2468. }
  2469. }
  2470. if (filterActive) {
  2471. for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
  2472. var pane = _c[_b];
  2473. pane.s.showFiltered = true;
  2474. }
  2475. }
  2476. }
  2477. }
  2478. for (var _d = 0, _e = this.s.panes; _d < _e.length; _d++) {
  2479. var pane = _e[_d];
  2480. pane.rebuildPane(undefined, Object.keys(this.s.serverData).length > 0 ? this.s.serverData : undefined);
  2481. $$1(this.dom.panes).append(pane.dom.container);
  2482. }
  2483. // If the layout is set to auto then the panes need to be resized to their best fit
  2484. if (this.c.layout === 'auto') {
  2485. this.resizePanes();
  2486. }
  2487. // Reset the paging if that has been saved in the state
  2488. if (!this.s.stateRead && loadedFilter !== null && loadedFilter !== undefined) {
  2489. this.s.dt.page((loadedFilter.start / this.s.dt.page.len()));
  2490. this.s.dt.draw('page');
  2491. }
  2492. this.s.stateRead = true;
  2493. if (this.c.viewTotal && !this.c.cascadePanes) {
  2494. for (var _f = 0, _g = this.s.panes; _f < _g.length; _f++) {
  2495. var pane = _g[_f];
  2496. pane.updatePane();
  2497. }
  2498. }
  2499. this._updateFilterCount();
  2500. this._checkMessage();
  2501. // When a draw is called on the DataTable, update all of the panes incase the data in the DataTable has changed
  2502. table.on('preDraw.dtsps', function () {
  2503. if (!_this.s.updating) {
  2504. _this._updateFilterCount();
  2505. if ((_this.c.cascadePanes || _this.c.viewTotal) && !_this.s.dt.page.info().serverSide) {
  2506. _this.redrawPanes(_this.c.viewTotal);
  2507. }
  2508. else {
  2509. _this._updateSelection();
  2510. }
  2511. _this.s.filterPane = -1;
  2512. }
  2513. });
  2514. $$1(window).on('resize.dtsp', dataTable$1.util.throttle(function () {
  2515. _this.resizePanes();
  2516. }));
  2517. // Whenever a state save occurs store the selection list in the state object
  2518. this.s.dt.on('stateSaveParams.dtsp', function (e, settings, data) {
  2519. if (data.searchPanes === undefined) {
  2520. data.searchPanes = {};
  2521. }
  2522. data.searchPanes.selectionList = _this.s.selectionList;
  2523. });
  2524. if (this.s.dt.page.info().serverSide) {
  2525. table.off('page');
  2526. table.on('page', function () {
  2527. _this.s.page = _this.s.dt.page();
  2528. });
  2529. table.off('preXhr.dt');
  2530. table.on('preXhr.dt', function (e, settings, data) {
  2531. if (data.searchPanes === undefined) {
  2532. data.searchPanes = {};
  2533. }
  2534. if (data.searchPanes_null === undefined) {
  2535. data.searchPanes_null = {};
  2536. }
  2537. // Count how many filters are being applied
  2538. var filterCount = 0;
  2539. for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
  2540. var pane = _a[_i];
  2541. var src = _this.s.dt.column(pane.s.index).dataSrc();
  2542. if (data.searchPanes[src] === undefined) {
  2543. data.searchPanes[src] = {};
  2544. }
  2545. if (data.searchPanes_null[src] === undefined) {
  2546. data.searchPanes_null[src] = {};
  2547. }
  2548. if (pane.s.dtPane !== undefined) {
  2549. var rowData = pane.s.dtPane.rows({ selected: true }).data().toArray();
  2550. for (var i = 0; i < rowData.length; i++) {
  2551. data.searchPanes[src][i] = rowData[i].filter;
  2552. if (data.searchPanes[src][i] === null) {
  2553. data.searchPanes_null[src][i] = true;
  2554. }
  2555. filterCount++;
  2556. }
  2557. }
  2558. }
  2559. if (_this.c.viewTotal) {
  2560. _this._prepViewTotal(filterCount);
  2561. }
  2562. // If there is a filter to be applied, then we need to read from the start of the result set
  2563. // and set the paging to 0. This matches the behaviour of client side processing
  2564. if (filterCount > 0) {
  2565. // If the number of filters has changed we need to read from the start of the
  2566. // result set and reset the paging
  2567. if (filterCount !== _this.s.filterCount) {
  2568. data.start = 0;
  2569. _this.s.page = 0;
  2570. }
  2571. // Otherwise it is a paging request and we need to read from whatever the paging has been set to
  2572. else {
  2573. data.start = _this.s.page * _this.s.dt.page.len();
  2574. }
  2575. _this.s.dt.page(_this.s.page);
  2576. _this.s.filterCount = filterCount;
  2577. }
  2578. });
  2579. }
  2580. else {
  2581. table.on('preXhr.dt', function (e, settings, data) {
  2582. for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
  2583. var pane = _a[_i];
  2584. pane.clearData();
  2585. }
  2586. });
  2587. }
  2588. // If the data is reloaded from the server then it is possible that it has changed completely,
  2589. // so we need to rebuild the panes
  2590. this.s.dt.on('xhr', function (e, settings, json, xhr) {
  2591. if (settings.nTable !== _this.s.dt.table().node()) {
  2592. return;
  2593. }
  2594. var processing = false;
  2595. if (!_this.s.dt.page.info().serverSide) {
  2596. _this.s.dt.one('preDraw', function () {
  2597. if (processing) {
  2598. return;
  2599. }
  2600. var page = _this.s.dt.page();
  2601. processing = true;
  2602. _this.s.updating = true;
  2603. $$1(_this.dom.panes).empty();
  2604. for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
  2605. var pane = _a[_i];
  2606. pane.clearData(); // Clears all of the bins and will mean that the data has to be re-read
  2607. // Pass a boolean to say whether this is the last choice made for maintaining selections
  2608. // when rebuilding
  2609. pane.rebuildPane(_this.s.selectionList[_this.s.selectionList.length - 1] !== undefined ?
  2610. pane.s.index === _this.s.selectionList[_this.s.selectionList.length - 1].index :
  2611. false, undefined, undefined, true);
  2612. $$1(_this.dom.panes).append(pane.dom.container);
  2613. }
  2614. if (!_this.s.dt.page.info().serverSide) {
  2615. _this.s.dt.draw();
  2616. }
  2617. _this.s.updating = false;
  2618. if (_this.c.cascadePanes || _this.c.viewTotal) {
  2619. _this.redrawPanes(_this.c.cascadePanes);
  2620. }
  2621. else {
  2622. _this._updateSelection();
  2623. }
  2624. _this._checkMessage();
  2625. _this.s.dt.one('draw', function () {
  2626. _this.s.updating = true;
  2627. _this.s.dt.page(page).draw(false);
  2628. _this.s.updating = false;
  2629. });
  2630. });
  2631. }
  2632. });
  2633. // PreSelect any selections which have been defined using the preSelect option
  2634. for (var _h = 0, _j = this.s.panes; _h < _j.length; _h++) {
  2635. var pane = _j[_h];
  2636. if (pane !== undefined &&
  2637. pane.s.dtPane !== undefined &&
  2638. ((pane.s.colOpts.preSelect !== undefined && pane.s.colOpts.preSelect.length > 0) ||
  2639. (pane.customPaneSettings !== null &&
  2640. pane.customPaneSettings.preSelect !== undefined &&
  2641. pane.customPaneSettings.preSelect.length > 0))) {
  2642. var tableLength = pane.s.dtPane.rows().data().toArray().length;
  2643. for (var i = 0; i < tableLength; i++) {
  2644. if (pane.s.colOpts.preSelect.indexOf(pane.s.dtPane.cell(i, 0).data()) !== -1 ||
  2645. (pane.customPaneSettings !== null &&
  2646. pane.customPaneSettings.preSelect !== undefined &&
  2647. pane.customPaneSettings.preSelect.indexOf(pane.s.dtPane.cell(i, 0).data()) !== -1)) {
  2648. pane.s.dtPane.row(i).select();
  2649. }
  2650. }
  2651. pane.updateTable();
  2652. }
  2653. }
  2654. if (this.s.selectionList !== undefined && this.s.selectionList.length > 0) {
  2655. var last = this.s.selectionList[this.s.selectionList.length - 1].index;
  2656. for (var _k = 0, _l = this.s.panes; _k < _l.length; _k++) {
  2657. var pane = _l[_k];
  2658. pane.s.lastSelect = (pane.s.index === last);
  2659. }
  2660. }
  2661. // If cascadePanes is active then make the previous selections in the order they were previously
  2662. if (this.s.selectionList.length > 0 && this.c.cascadePanes) {
  2663. this._cascadeRegen(this.s.selectionList, this.s.selectionList.length);
  2664. }
  2665. // Update the title bar to show how many filters have been selected
  2666. this._updateFilterCount();
  2667. // If the table is destroyed and restarted then clear the selections so that they do not persist.
  2668. table.on('destroy.dtsps', function () {
  2669. for (var _i = 0, _a = _this.s.panes; _i < _a.length; _i++) {
  2670. var pane = _a[_i];
  2671. pane.destroy();
  2672. }
  2673. table.off('.dtsps');
  2674. $$1(_this.dom.clearAll).off('.dtsps');
  2675. $$1(_this.dom.container).remove();
  2676. _this.clearSelections();
  2677. });
  2678. // When the clear All button has been pressed clear all of the selections in the panes
  2679. if (this.c.clear) {
  2680. $$1(this.dom.clearAll).on('click.dtsps', function () {
  2681. _this.clearSelections();
  2682. });
  2683. }
  2684. table.settings()[0]._searchPanes = this;
  2685. this.s.dt.state.save();
  2686. };
  2687. SearchPanes.prototype._prepViewTotal = function (selectTotal) {
  2688. var filterPane = this.s.filterPane;
  2689. var filterActive = false;
  2690. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2691. var pane = _a[_i];
  2692. if (pane.s.dtPane !== undefined) {
  2693. var selectLength = pane.s.dtPane.rows({ selected: true }).data().toArray().length;
  2694. // If filterPane === -1 then a pane with a selection has not been found yet,
  2695. // so set filterPane to that panes index
  2696. if (selectLength > 0 && filterPane === -1) {
  2697. filterPane = pane.s.index;
  2698. filterActive = true;
  2699. }
  2700. // Then if another pane is found with a selection then set filterPane to null to
  2701. // show that multiple panes have selections present
  2702. else if (selectLength > 0) {
  2703. filterPane = null;
  2704. }
  2705. }
  2706. }
  2707. if (selectTotal !== null && selectTotal !== 0) {
  2708. filterPane = null;
  2709. }
  2710. // Update all of the panes to reflect the current state of the filters
  2711. for (var _b = 0, _c = this.s.panes; _b < _c.length; _b++) {
  2712. var pane = _c[_b];
  2713. if (pane.s.dtPane !== undefined) {
  2714. pane.s.filteringActive = true;
  2715. if ((filterPane !== -1 && filterPane !== null && filterPane === pane.s.index) ||
  2716. filterActive === false) {
  2717. pane.s.filteringActive = false;
  2718. }
  2719. }
  2720. }
  2721. };
  2722. /**
  2723. * Updates the number of filters that have been applied in the title
  2724. */
  2725. SearchPanes.prototype._updateFilterCount = function () {
  2726. var filterCount = 0;
  2727. // Add the number of all of the filters throughout the panes
  2728. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2729. var pane = _a[_i];
  2730. if (pane.s.dtPane !== undefined) {
  2731. filterCount += pane.getPaneCount();
  2732. }
  2733. }
  2734. // Run the message through the internationalisation method to improve readability
  2735. var message = this.s.dt.i18n('searchPanes.title', this.c.i18n.title, filterCount);
  2736. $$1(this.dom.title).text(message);
  2737. if (this.c.filterChanged !== undefined && typeof this.c.filterChanged === 'function') {
  2738. this.c.filterChanged.call(this.s.dt, filterCount);
  2739. }
  2740. if (filterCount === 0) {
  2741. $$1(this.dom.clearAll).addClass(this.classes.disabledButton).attr('disabled', 'true');
  2742. }
  2743. else {
  2744. $$1(this.dom.clearAll).removeClass(this.classes.disabledButton).removeAttr('disabled');
  2745. }
  2746. };
  2747. /**
  2748. * Updates the selectionList when cascade is not in place
  2749. */
  2750. SearchPanes.prototype._updateSelection = function () {
  2751. this.s.selectionList = [];
  2752. for (var _i = 0, _a = this.s.panes; _i < _a.length; _i++) {
  2753. var pane = _a[_i];
  2754. if (pane.s.dtPane !== undefined) {
  2755. this.s.selectionList.push({
  2756. index: pane.s.index,
  2757. protect: false,
  2758. rows: pane.s.dtPane.rows({ selected: true }).data().toArray()
  2759. });
  2760. }
  2761. }
  2762. this.s.dt.state.save();
  2763. };
  2764. SearchPanes.version = '1.3.0';
  2765. SearchPanes.classes = {
  2766. clear: 'dtsp-clear',
  2767. clearAll: 'dtsp-clearAll',
  2768. container: 'dtsp-searchPanes',
  2769. disabledButton: 'dtsp-disabledButton',
  2770. emptyMessage: 'dtsp-emptyMessage',
  2771. hide: 'dtsp-hidden',
  2772. panes: 'dtsp-panesContainer',
  2773. search: 'dtsp-search',
  2774. title: 'dtsp-title',
  2775. titleRow: 'dtsp-titleRow'
  2776. };
  2777. // Define SearchPanes default options
  2778. SearchPanes.defaults = {
  2779. cascadePanes: false,
  2780. clear: true,
  2781. columns: [],
  2782. container: function (dt) {
  2783. return dt.table().container();
  2784. },
  2785. filterChanged: undefined,
  2786. i18n: {
  2787. clearMessage: 'Clear All',
  2788. clearPane: '&times;',
  2789. collapse: {
  2790. 0: 'SearchPanes',
  2791. _: 'SearchPanes (%d)'
  2792. },
  2793. count: '{total}',
  2794. countFiltered: '{shown} ({total})',
  2795. emptyMessage: '<em>No data</em>',
  2796. emptyPanes: 'No SearchPanes',
  2797. loadMessage: 'Loading Search Panes...',
  2798. title: 'Filters Active - %d'
  2799. },
  2800. layout: 'auto',
  2801. order: [],
  2802. panes: [],
  2803. viewTotal: false
  2804. };
  2805. return SearchPanes;
  2806. }());
  2807. /*! SearchPanes 1.3.0
  2808. * 2019-2020 SpryMedia Ltd - datatables.net/license
  2809. */
  2810. // DataTables extensions common UMD. Note that this allows for AMD, CommonJS
  2811. // (with window and jQuery being allowed as parameters to the returned
  2812. // function) or just default browser loading.
  2813. (function (factory) {
  2814. if (typeof define === 'function' && define.amd) {
  2815. // AMD
  2816. define(['jquery', 'datatables.net'], function ($) {
  2817. return factory($, window, document);
  2818. });
  2819. }
  2820. else if (typeof exports === 'object') {
  2821. // CommonJS
  2822. module.exports = function (root, $) {
  2823. if (!root) {
  2824. root = window;
  2825. }
  2826. if (!$ || !$.fn.dataTable) {
  2827. // eslint-disable-next-line @typescript-eslint/no-var-requires
  2828. $ = require('datatables.net')(root, $).$;
  2829. }
  2830. return factory($, root, root.document);
  2831. };
  2832. }
  2833. else {
  2834. // Browser - assume jQuery has already been loaded
  2835. factory(window.jQuery, window, document);
  2836. }
  2837. }(function ($, window, document) {
  2838. setJQuery($);
  2839. setJQuery$1($);
  2840. var dataTable = $.fn.dataTable;
  2841. $.fn.dataTable.SearchPanes = SearchPanes;
  2842. $.fn.DataTable.SearchPanes = SearchPanes;
  2843. $.fn.dataTable.SearchPane = SearchPane;
  2844. $.fn.DataTable.SearchPane = SearchPane;
  2845. var apiRegister = $.fn.dataTable.Api.register;
  2846. apiRegister('searchPanes()', function () {
  2847. return this;
  2848. });
  2849. apiRegister('searchPanes.clearSelections()', function () {
  2850. return this.iterator('table', function (ctx) {
  2851. if (ctx._searchPanes) {
  2852. ctx._searchPanes.clearSelections();
  2853. }
  2854. });
  2855. });
  2856. apiRegister('searchPanes.rebuildPane()', function (targetIdx, maintainSelections) {
  2857. return this.iterator('table', function (ctx) {
  2858. if (ctx._searchPanes) {
  2859. ctx._searchPanes.rebuild(targetIdx, maintainSelections);
  2860. }
  2861. });
  2862. });
  2863. apiRegister('searchPanes.resizePanes()', function () {
  2864. var ctx = this.context[0];
  2865. return ctx._searchPanes ?
  2866. ctx._searchPanes.resizePanes() :
  2867. null;
  2868. });
  2869. apiRegister('searchPanes.container()', function () {
  2870. var ctx = this.context[0];
  2871. return ctx._searchPanes
  2872. ? ctx._searchPanes.getNode()
  2873. : null;
  2874. });
  2875. $.fn.dataTable.ext.buttons.searchPanesClear = {
  2876. action: function (e, dt, node, config) {
  2877. dt.searchPanes.clearSelections();
  2878. },
  2879. text: 'Clear Panes'
  2880. };
  2881. $.fn.dataTable.ext.buttons.searchPanes = {
  2882. action: function (e, dt, node, config) {
  2883. e.stopPropagation();
  2884. this.popover(config._panes.getNode(), {
  2885. align: 'dt-container'
  2886. });
  2887. config._panes.rebuild(undefined, true);
  2888. },
  2889. config: {},
  2890. init: function (dt, node, config) {
  2891. var panes = new $.fn.dataTable.SearchPanes(dt, $.extend({
  2892. filterChanged: function (count) {
  2893. dt.button(node).text(dt.i18n('searchPanes.collapse', panes.c.i18n.collapse, count));
  2894. }
  2895. }, config.config));
  2896. var message = dt.i18n('searchPanes.collapse', panes.c.i18n.collapse, 0);
  2897. dt.button(node).text(message);
  2898. config._panes = panes;
  2899. },
  2900. text: 'Search Panes'
  2901. };
  2902. function _init(settings, options, fromPre) {
  2903. if (options === void 0) { options = null; }
  2904. if (fromPre === void 0) { fromPre = false; }
  2905. var api = new dataTable.Api(settings);
  2906. var opts = options
  2907. ? options
  2908. : api.init().searchPanes || dataTable.defaults.searchPanes;
  2909. var searchPanes = new SearchPanes(api, opts, fromPre);
  2910. var node = searchPanes.getNode();
  2911. return node;
  2912. }
  2913. // Attach a listener to the document which listens for DataTables initialisation
  2914. // events so we can automatically initialise
  2915. $(document).on('preInit.dt.dtsp', function (e, settings, json) {
  2916. if (e.namespace !== 'dt') {
  2917. return;
  2918. }
  2919. if (settings.oInit.searchPanes ||
  2920. dataTable.defaults.searchPanes) {
  2921. if (!settings._searchPanes) {
  2922. _init(settings, null, true);
  2923. }
  2924. }
  2925. });
  2926. // DataTables `dom` feature option
  2927. dataTable.ext.feature.push({
  2928. cFeature: 'P',
  2929. fnInit: _init
  2930. });
  2931. // DataTables 2 layout feature
  2932. if (dataTable.ext.features) {
  2933. dataTable.ext.features.register('searchPanes', _init);
  2934. }
  2935. }));
  2936. }());