1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-13 11:22:33 +02:00
TableFilter/doc/file/src/modules/gridLayout.js.html
2015-08-02 18:27:59 +10:00

440 lines
17 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base data-ice="baseUrl" href="../../../">
<title data-ice="title">src/modules/gridLayout.js | TableFilter v0.0.0 API Document</title>
<link type="text/css" rel="stylesheet" href="css/style.css">
<link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css">
<script src="script/prettify/prettify.js"></script>
</head>
<body class="layout-container">
<header>
<a href="./">Home</a>
<a href="identifiers.html">Identifier</a>
<a href="source.html">Source</a>
<a data-ice="repoURL" href="https://github.com/koalyptus/TableFilter.git" class="repo-url-github">Repository</a>
<div class="search-box">
<span>
<img src="./image/search.png">
<span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span>
</span>
<ul class="search-result"></ul>
</div>
</header>
<nav class="navigation" data-ice="nav"><div data-ice="classWrap">
<h2>Class</h2>
<ul>
<li data-ice="classDoc"><span><a href="class/src/extensions/advancedGrid/adapterEzEditTable.js~AdapterEzEditTable.html">AdapterEzEditTable</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/extensions/sort/adapterSortabletable.js~AdapterSortableTable.html">AdapterSortableTable</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/alternateRows.js~AlternateRows.html">AlternateRows</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/checkList.js~CheckList.html">CheckList</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/clearButton.js~ClearButton.html">ClearButton</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/extensions/colOps/colOps.js~ColOps.html">ColOps</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/extensions/colsVisibility/colsVisibility.js~ColsVisibility.html">ColsVisibility</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/dropdown.js~Dropdown.html">Dropdown</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/extensions/filtersVisibility/filtersVisibility.js~FiltersVisibility.html">FiltersVisibility</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/gridLayout.js~GridLayout.html">GridLayout</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/help.js~Help.html">Help</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/highlightKeywords.js~HighlightKeyword.html">HighlightKeyword</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/loader.js~Loader.html">Loader</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/paging.js~Paging.html">Paging</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/popupFilter.js~PopupFilter.html">PopupFilter</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/rowsCounter.js~RowsCounter.html">RowsCounter</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/statusBar.js~StatusBar.html">StatusBar</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/modules/store.js~Store.html">Store</a></span></li>
<li data-ice="classDoc"><span><a href="class/src/tablefilter.js~TableFilter.html">TableFilter</a></span></li>
</ul>
</div>
</nav>
<div class="content" data-ice="content"><h1 data-ice="title">src/modules/gridLayout.js</h1>
<pre class="source-code line-number"><code class="prettyprint linenums" data-ice="content">import Dom from &apos;../dom&apos;;
import Types from &apos;../types&apos;;
import Event from &apos;../event&apos;;
export class GridLayout{
/**
* Grid layout, table with fixed headers
* @param {Object} tf TableFilter instance
*/
constructor(tf) {
var f = tf.config();
//defines grid width
this.gridWidth = f.grid_width || null;
//defines grid height
this.gridHeight = f.grid_height || null;
//defines css class for main container
this.gridMainContCssClass = f.grid_cont_css_class || &apos;grd_Cont&apos;;
//defines css class for div containing table
this.gridContCssClass = f.grid_tbl_cont_css_class || &apos;grd_tblCont&apos;;
//defines css class for div containing headers&apos; table
this.gridHeadContCssClass = f.grid_tblHead_cont_css_class ||
&apos;grd_headTblCont&apos;;
//defines css class for div containing rows counter, paging etc.
this.gridInfDivCssClass = f.grid_inf_grid_css_class || &apos;grd_inf&apos;;
//defines which row contains column headers
this.gridHeadRowIndex = f.grid_headers_row_index || 0;
//array of headers row indexes to be placed in header table
this.gridHeadRows = f.grid_headers_rows || [0];
//generate filters in table headers
this.gridEnableFilters = f.grid_enable_default_filters!==undefined ?
f.grid_enable_default_filters : true;
//default col width
this.gridDefaultColWidth = f.grid_default_col_width || &apos;100px&apos;;
//enables/disables columns resizer
// this.gridEnableColResizer = f.grid_enable_cols_resizer!==undefined ?
// f.grid_enable_cols_resizer : false;
// //defines col resizer script path
// this.gridColResizerPath = f.grid_cont_col_resizer_path ||
// this.basePath+&apos;TFExt_ColsResizer/TFExt_ColsResizer.js&apos;;
this.gridColElms = [];
//div containing grid elements if grid_layout true
this.prfxMainTblCont = &apos;gridCont_&apos;;
//div containing table if grid_layout true
this.prfxTblCont = &apos;tblCont_&apos;;
//div containing headers table if grid_layout true
this.prfxHeadTblCont = &apos;tblHeadCont_&apos;;
//headers&apos; table if grid_layout true
this.prfxHeadTbl = &apos;tblHead_&apos;;
//id of td containing the filter if grid_layout true
this.prfxGridFltTd = &apos;_td_&apos;;
//id of th containing column header if grid_layout true
this.prfxGridTh = &apos;tblHeadTh_&apos;;
this.tf = tf;
}
/**
* Generates a grid with fixed headers
*/
init(){
var tf = this.tf;
var f = tf.config();
var tbl = tf.tbl;
if(!tf.gridLayout){
return;
}
tf.isExternalFlt = true;
// default width of 100px if column widths not set
if(!tf.hasColWidths){
tf.colWidths = [];
for(var k=0; k&lt;tf.nbCells; k++){
var colW,
cell = tbl.rows[this.gridHeadRowIndex].cells[k];
if(cell.width !== &apos;&apos;){
colW = cell.width;
} else if(cell.style.width !== &apos;&apos;){
colW = parseInt(cell.style.width, 10);
} else {
colW = this.gridDefaultColWidth;
}
tf.colWidths[k] = colW;
}
tf.hasColWidths = true;
}
tf.setColWidths(this.gridHeadRowIndex);
var tblW;//initial table width
if(tbl.width !== &apos;&apos;){
tblW = tbl.width;
}
else if(tbl.style.width !== &apos;&apos;){
tblW = parseInt(tbl.style.width, 10);
} else {
tblW = tbl.clientWidth;
}
//Main container: it will contain all the elements
this.tblMainCont = Dom.create(&apos;div&apos;,
[&apos;id&apos;, this.prfxMainTblCont + tf.id]);
this.tblMainCont.className = this.gridMainContCssClass;
if(this.gridWidth){
this.tblMainCont.style.width = this.gridWidth;
}
tbl.parentNode.insertBefore(this.tblMainCont, tbl);
//Table container: div wrapping content table
this.tblCont = Dom.create(&apos;div&apos;,[&apos;id&apos;, this.prfxTblCont + tf.id]);
this.tblCont.className = this.gridContCssClass;
if(this.gridWidth){
if(this.gridWidth.indexOf(&apos;%&apos;) != -1){
console.log(this.gridWidth);
this.tblCont.style.width = &apos;100%&apos;;
} else {
this.tblCont.style.width = this.gridWidth;
}
}
if(this.gridHeight){
this.tblCont.style.height = this.gridHeight;
}
tbl.parentNode.insertBefore(this.tblCont, tbl);
var t = tbl.parentNode.removeChild(tbl);
this.tblCont.appendChild(t);
//In case table width is expressed in %
if(tbl.style.width === &apos;&apos;){
tbl.style.width = (tf._containsStr(&apos;%&apos;, tblW) ?
tbl.clientWidth : tblW) + &apos;px&apos;;
}
var d = this.tblCont.parentNode.removeChild(this.tblCont);
this.tblMainCont.appendChild(d);
//Headers table container: div wrapping headers table
this.headTblCont = Dom.create(
&apos;div&apos;,[&apos;id&apos;, this.prfxHeadTblCont + tf.id]);
this.headTblCont.className = this.gridHeadContCssClass;
if(this.gridWidth){
if(this.gridWidth.indexOf(&apos;%&apos;) != -1){
console.log(this.gridWidth);
this.headTblCont.style.width = &apos;100%&apos;;
} else {
this.headTblCont.style.width = this.gridWidth;
}
}
//Headers table
this.headTbl = Dom.create(&apos;table&apos;, [&apos;id&apos;, this.prfxHeadTbl + tf.id]);
var tH = Dom.create(&apos;tHead&apos;); //IE&lt;7 needs it
//1st row should be headers row, ids are added if not set
//Those ids are used by the sort feature
var hRow = tbl.rows[this.gridHeadRowIndex];
var sortTriggers = [];
for(var n=0; n&lt;tf.nbCells; n++){
var c = hRow.cells[n];
var thId = c.getAttribute(&apos;id&apos;);
if(!thId || thId===&apos;&apos;){
thId = this.prfxGridTh+n+&apos;_&apos;+tf.id;
c.setAttribute(&apos;id&apos;, thId);
}
sortTriggers.push(thId);
}
//Filters row is created
var filtersRow = Dom.create(&apos;tr&apos;);
if(this.gridEnableFilters &amp;&amp; tf.fltGrid){
tf.externalFltTgtIds = [];
for(var j=0; j&lt;tf.nbCells; j++){
var fltTdId = tf.prfxFlt+j+ this.prfxGridFltTd +tf.id;
var cl = Dom.create(tf.fltCellTag, [&apos;id&apos;, fltTdId]);
filtersRow.appendChild(cl);
tf.externalFltTgtIds[j] = fltTdId;
}
}
//Headers row are moved from content table to headers table
for(var i=0; i&lt;this.gridHeadRows.length; i++){
var headRow = tbl.rows[this.gridHeadRows[0]];
tH.appendChild(headRow);
}
this.headTbl.appendChild(tH);
if(tf.filtersRowIndex === 0){
tH.insertBefore(filtersRow,hRow);
} else {
tH.appendChild(filtersRow);
}
this.headTblCont.appendChild(this.headTbl);
this.tblCont.parentNode.insertBefore(this.headTblCont, this.tblCont);
//THead needs to be removed in content table for sort feature
var thead = Dom.tag(tbl, &apos;thead&apos;);
if(thead.length&gt;0){
tbl.removeChild(thead[0]);
}
//Headers table style
this.headTbl.style.tableLayout = &apos;fixed&apos;;
tbl.style.tableLayout = &apos;fixed&apos;;
this.headTbl.cellPadding = tbl.cellPadding;
this.headTbl.cellSpacing = tbl.cellSpacing;
// this.headTbl.style.width = tbl.style.width;
//content table without headers needs col widths to be reset
tf.setColWidths(0, this.headTbl);
//Headers container width
// this.headTblCont.style.width = this.tblCont.clientWidth+&apos;px&apos;;
tbl.style.width = &apos;&apos;;
//
this.headTbl.style.width = tbl.clientWidth + &apos;px&apos;;
//
//scroll synchronisation
Event.add(this.tblCont, &apos;scroll&apos;, (evt)=&gt; {
var elm = Event.target(evt);
var scrollLeft = elm.scrollLeft;
this.headTblCont.scrollLeft = scrollLeft;
//New pointerX calc taking into account scrollLeft
// if(!o.isPointerXOverwritten){
// try{
// o.Evt.pointerX = function(evt){
// var e = evt || global.event;
// var bdScrollLeft = tf_StandardBody().scrollLeft +
// scrollLeft;
// return (e.pageX + scrollLeft) ||
// (e.clientX + bdScrollLeft);
// };
// o.isPointerXOverwritten = true;
// } catch(err) {
// o.isPointerXOverwritten = false;
// }
// }
});
//Configure sort extension if any
var sort = (f.extensions || []).filter(function(itm){
return itm.name === &apos;sort&apos;;
});
if(sort.length === 1){
sort[0].async_sort = true;
sort[0].trigger_ids = sortTriggers;
}
// if(this.gridEnableColResizer){
// if(!tf.hasExtensions){
// tf.extensions = {
// name:[&apos;ColumnsResizer_&apos;+tf.id],
// src:[this.gridColResizerPath],
// description:[&apos;Columns Resizing&apos;],
// initialize:[function(o){
// o.SetColsResizer(&apos;ColumnsResizer_&apos;+o.id);}]
// };
// tf.hasExtensions = true;
// } else {
// if(!tf._containsStr(
// &apos;colsresizer&apos;,
// Str.lower(tf.extensions.src.toString())) ){
// tf.extensions.name.push(&apos;ColumnsResizer_&apos;+tf.id);
// tf.extensions.src.push(tf.gridColResizerPath);
// tf.extensions.description.push(&apos;Columns Resizing&apos;);
// tf.extensions.initialize.push(function(o){
// o.SetColsResizer(&apos;ColumnsResizer_&apos;+o.id);});
// }
// }
// }
//Default columns resizer properties for grid layout
// f.col_resizer_cols_headers_table = this.headTbl.getAttribute(&apos;id&apos;);
// f.col_resizer_cols_headers_index = this.gridHeadRowIndex;
// f.col_resizer_width_adjustment = 0;
// f.col_enable_text_ellipsis = false;
//Cols generation for all browsers excepted IE&lt;=7
this.tblHasColTag = Dom.tag(tbl, &apos;col&apos;).length &gt; 0 ? true : false;
//Col elements are enough to keep column widths after sorting and
//filtering
var createColTags = function(){
for(var k=(tf.nbCells-1); k&gt;=0; k--){
var col = Dom.create(&apos;col&apos;, [&apos;id&apos;, tf.id+&apos;_col_&apos;+k]);
tbl.insertBefore(col, tbl.firstChild);
col.style.width = tf.colWidths[k];
this.gridColElms[k] = col;
}
this.tblHasColTag = true;
};
if(!this.tblHasColTag){
createColTags.call(this);
} else {
var cols = Dom.tag(tbl, &apos;col&apos;);
for(var ii=0; ii&lt;tf.nbCells; ii++){
cols[ii].setAttribute(&apos;id&apos;, tf.id+&apos;_col_&apos;+ii);
cols[ii].style.width = tf.colWidths[ii];
this.gridColElms.push(cols[ii]);
}
}
var afterColResizedFn = Types.isFn(f.on_after_col_resized) ?
f.on_after_col_resized : null;
f.on_after_col_resized = function(o, colIndex){
if(!colIndex){
return;
}
var w = o.crWColsRow.cells[colIndex].style.width;
var col = o.gridColElms[colIndex];
col.style.width = w;
var thCW = o.crWColsRow.cells[colIndex].clientWidth;
var tdCW = o.crWRowDataTbl.cells[colIndex].clientWidth;
if(thCW != tdCW){
o.headTbl.style.width = tbl.clientWidth+&apos;px&apos;;
}
if(afterColResizedFn){
afterColResizedFn.call(null,o,colIndex);
}
};
if(tbl.clientWidth !== this.headTbl.clientWidth){
tbl.style.width = this.headTbl.clientWidth+&apos;px&apos;;
}
}
/**
* Removes the grid layout
*/
destroy(){
var tf = this.tf;
var tbl = tf.tbl;
if(!tf.gridLayout){
return;
}
var t = tbl.parentNode.removeChild(tbl);
this.tblMainCont.parentNode.insertBefore(t, this.tblMainCont);
this.tblMainCont.parentNode.removeChild(this.tblMainCont);
this.tblMainCont = null;
this.headTblCont = null;
this.headTbl = null;
this.tblCont = null;
tbl.outerHTML = tf.sourceTblHtml;
//needed to keep reference of table element
tbl = Dom.id(tf.id);
}
}</code></pre>
</div>
<footer class="footer">
Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(0.1.4)</span></a>
</footer>
<script src="script/search_index.js"></script>
<script src="script/search.js"></script>
<script src="script/pretty-print.js"></script>
<script src="script/inherited-summary.js"></script>
<script src="script/test-summary.js"></script>
<script src="script/inner-link.js"></script>
<script src="script/patch-for-local.js"></script>
</body>
</html>