MCPcopy Create free account
hub / github.com/breck7/scroll / _fnCalculateColumnWidths

Function _fnCalculateColumnWidths

external/.datatables.js:4892–5077  ·  view source on GitHub ↗

* Calculate the width of columns for the table * @param {object} settings dataTables settings object * @memberof DataTable#oApi

(settings)

Source from the content-addressed store, hash-verified

4890 * @memberof DataTable#oApi
4891 */
4892 function _fnCalculateColumnWidths(settings) {
4893 // Not interested in doing column width calculation if auto-width is disabled
4894 if (!settings.oFeatures.bAutoWidth) {
4895 return
4896 }
4897
4898 var table = settings.nTable,
4899 columns = settings.aoColumns,
4900 scroll = settings.oScroll,
4901 scrollY = scroll.sY,
4902 scrollX = scroll.sX,
4903 scrollXInner = scroll.sXInner,
4904 visibleColumns = _fnGetColumns(settings, "bVisible"),
4905 tableWidthAttr = table.getAttribute("width"), // from DOM element
4906 tableContainer = table.parentNode,
4907 i,
4908 column,
4909 columnIdx
4910
4911 var styleWidth = table.style.width
4912
4913 // If there is no width applied as a CSS style or as an attribute, we assume that
4914 // the width is intended to be 100%, which is usually is in CSS, but it is very
4915 // difficult to correctly parse the rules to get the final result.
4916 if (!styleWidth && !tableWidthAttr) {
4917 table.style.width = "100%"
4918 styleWidth = "100%"
4919 }
4920
4921 if (styleWidth && styleWidth.indexOf("%") !== -1) {
4922 tableWidthAttr = styleWidth
4923 }
4924
4925 // Let plug-ins know that we are doing a recalc, in case they have changed any of the
4926 // visible columns their own way (e.g. Responsive uses display:none).
4927 _fnCallbackFire(settings, null, "column-calc", { visible: visibleColumns }, false)
4928
4929 // Construct a single row, worst case, table with the widest
4930 // node in the data, assign any user defined widths, then insert it into
4931 // the DOM and allow the browser to do all the hard work of calculating
4932 // table widths
4933 var tmpTable = $(table.cloneNode()).css("visibility", "hidden").removeAttr("id")
4934
4935 // Clean up the table body
4936 tmpTable.append("<tbody>")
4937 var tr = $("<tr/>").appendTo(tmpTable.find("tbody"))
4938
4939 // Clone the table header and footer - we can't use the header / footer
4940 // from the cloned table, since if scrolling is active, the table's
4941 // real header and footer are contained in different table tags
4942 tmpTable.append($(settings.nTHead).clone()).append($(settings.nTFoot).clone())
4943
4944 // Remove any assigned widths from the footer (from scrolling)
4945 tmpTable.find("tfoot th, tfoot td").css("width", "")
4946
4947 // Apply custom sizing to the cloned header
4948 tmpTable.find("thead th, thead td").each(function () {
4949 // Get the `width` from the header layout

Callers 1

_fnAdjustColumnSizingFunction · 0.85

Calls 13

_fnGetColumnsFunction · 0.85
_fnCallbackFireFunction · 0.85
_fnColumnsSumWidthFunction · 0.85
_fnGetMaxLenStringFunction · 0.85
_fnStringToCssFunction · 0.85
bindResizeFunction · 0.85
getAttributeMethod · 0.80
indexOfMethod · 0.80
eachMethod · 0.80
removeMethod · 0.80
$Function · 0.70
findMethod · 0.45

Tested by

no test coverage detected