-
-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
html thead is always visible at the top of the screen not when scrolling down #232
Comments
seriously? |
well i didn't know how else to explain the problem. I don't think you have to read the plugin part. |
Also i mean you can use this because it works here http://jsfiddle.net/833eLyod/18/ |
i can help you fix a broke jsfiddle because I can run the code there. I cant run this code. Also, I dont know rails |
so whats broken and what do i need to fix. |
there is nothing broken here: http://jsfiddle.net/833eLyod/18/ |
okay I found what the problem is there is yum bar at the top and that scrolls which is causing the table header not to scroll is there a way to have both of them scroll the yum bar and the table header |
🎉 |
here is what i have for the javascript and css: $(document).ready(function(){
}); .yamm.navbar.navbar-inverse.navbar-fixed-top.navbar-at-top.queue-top-bar { position:absolute; } table.floatThead-table { } |
this issue makes absolutely no sense to me |
well here is the problem it works now but there is a little problem if you look at the first screen shot the table header doesn't align with the table unless i re size my browser window. I am trying to figure out why even after i used $table.floatThead({useAbsolutePositioning: false}); |
look, i can help you if you provide a jsfiddle that reproduces your problem. i cant help you by looking at code or screenshots. if you cant reproduce your problem on jsfiddle, then you dont know what your problem is, and you are in no position to ask anyone to help you solve it. |
did you read the docs? Events Given a table element $table that has been widgetized, a reflow event causes the header to realign itself to the correct position. This event must be triggered if the DOM is modifed in such a way that the widgetized table's location changes. |
Yeah i did read the docs. I used useAbsolutePositioning: false and $table.trigger('reflow') it didn't work for me still when i scroll the table header doesn't alight with the table. If you can't help then i understand but i pretty much did everything on the documentation. Even when you look at jsfiddle the table header doesn't align with the table. |
ok, |
You can look at this one even though it scrolls i don't think it aligns properly: http://jsfiddle.net/833eLyod/18/ |
hey so i finally got it to work for one view by adding this setTimeout(function(){$('.queue-display').trigger('reflow');},1000); but when my column gets bigger it doesn't align and i have to re size the window again for the table header to align. For something like this i have to re size the browser every time: http://jsfiddle.net/suj7ws01/ |
there is not javascript in that fiddle |
I am running the same javascript code: http://jsfiddle.net/833eLyod/18/. I think i know what the problem is. Your plugin is not working with dynamic table that uses javascript knockout to build the table. I am not sure if you can fix that . |
Here is a perfect example of jsfiddle: http://jsfiddle.net/6tpp23dd/. Like i said the rows are being dynamically created by knockout javascript. one the real application the table header scrolls but it's all bunched up together. |
yes, the plugin will not work with knockout because it does not know when knockout is done rendering. you need to tell it. maybe those are helpful. you basically need to setup some callback that gets called after knockout renders the table, and when that happens call I dont know knockout, so thats the best I can do here. |
if it;s something to do with the knockout why does it work when i resize the window even just a little bit. Is there a way to resize the window just even by a percent which could be a work around as of right now |
it works when you resize the window because this plugin will reflow itself when you do that. resizing the window is the same as calling you probably resize the window AFTER knockout finishes rendering, so it appears to fix the issue. the real fix is to have a callback when knockout finishes rendering |
okay I did exactly what you asked and i still have to resize my window for it work. tbody data-bind="foreach: { this.showAfterRender = function () {
|
ok, it looks like I cant help you. Sorry. |
I mean obviously something is broken with the plugin so i am understanding how can't not help me. |
Yes, which is why it works on the demo site |
I already tried that man. I read the stuff that provided too. |
either way, if you can provide a jsfiddle that runs, and reproduces your issue, i will look at it. otherwise this is a waste of time for both of us. I need a jsfiddle that has javascript css and html and when you run it, the same thing happens as on your site. I dont know how else to say this. You will probably need to learn how to use jsfiddle external resources, since you have not done this and it would be much easier to make one. it will be harder to make a jsfiddle with knockout, but that is what I require. I cannot solve your problem in my imagination, i need to work with real code. |
hey i got it to work by adding: setTimeout(function(){$('.queue-display').trigger('reflow');},1000); just in case if someone else is having the same problem. |
try adding this to the options: i think the problem is that your callback also you can try
good luck |
I take it back it works for some of the table but not the others. What you mean by moving it up to the parent component? do you mean parent component of .queue-display which is a div class name is queue-app. and i tried replace the .queue-display with queue-app that didn't work at all unless there is another way to do it. |
I dont know knockout, but since triggering reflow after rendering the table component does not work (but resizing window works) that tells me that your table isnt actually done rendering. Perhaps there is a parent component that you can use that will ensure your table is rendered when the callback gets called. |
what you mean by parent component? do you mean parent component of .queue-display which is a div class name is queue-app? |
|
there is this but this is for the columns:
|
I don't know knockout, so I don't know what you want me to do with that. |
Here is a jsfiddle: https://jsfiddle.net/9d38dek4/ |
This one doesn't align at all |
I think i am pretty sure i figure out what the problem is this time: Sometime it takes a while for the columns to build because it's striping data from the file and the table header already gets build before the column does. so if you set the times to 10 second or something it works but anything less than that for big view doesn't. Is there a way to tell it not to build the table header until the column is ready. |
The point of a jsfiddle is so that i can run the javascript code on it and see what happens. your fiddle contains the html generated by my plugin. This doesnt help me in any way. Include the html before the plugin runs. I have spent too much time on this issue. If you want further help, please consider donating to floatThead. Thanks. |
I am working in a rails app. I have a table on my screen and the table header always stays at the top doesn't move when i am scrolling down. I downloaded JQuery.floatThead plugin and required it in application.js script by doing //= require jquery_floatThead and then in the application.js file i called floatThead function but its not working. I am also using bootstrap. Here is my application.js file:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
//
// this brings in jquery, bootstrap, and all the defaults
//
// Note that usually, Rails uses require_tree . here. That requires
// everything in the current directory tree. I don't think we reallg
// want to do that for this app, though, because there will be a bid
// variety of things deployed.
//
// However, you probably DO want to require almost everything here, so
// it gets compiled into the one giant cached JS file. That is better
// than separate files for every page, usually.
//
//
PNotify.prototype.options.styling = "fontawesome";
// Set the auth token on all ajax requests, if we have one
$(document).ready(function() {
if (window.bpub.authToken) {
var token = encodeURIComponent(window.bpub.authToken);
$.ajaxSetup({
headers: {'Authorization' : 'Token token="' + token + '"'},
});
}
});
/*
Global error handler for all ajax problems. If you don't want this,
because you want to handle it yourself, then add the
global: false option as follows:
$.ajax({
url: url,
data: data,
global: false,
...
})
*/
$( document ).ajaxError(function( event, jqxhr, settings, thrownError ) {
var message = jqxhr.responseText;
if (jqxhr.responseJSON.error && jqxhr.responseJSON.error.message) {
message = jqxhr.responseJSON.error.message;
}
});
$(document).ready(function() {
});
// clean up all our yamm windows -- if they are long then they won't
// fit on the page properly.
$(document).ready(function() {
var resize_yamm = function() {
// 150 is somewhat arbitrary, want to fill up most of screen
// but still look like a dropdown, and don't overlap toolbars
});
// this will catch any error and email it to support
$(document).ready(function() {
window.onerror = function(errorMsg, url, lineNumber) {
var postUrl = window.bpub.queue_web_services_base + "/errors/send_to_support";
// disabling for now -- this is spamming
// $.ajax(
// { url: postUrl,
// data: { "message" : message },
// method: 'post',
// }
// );
};
});
$(document).ready(function() {
});
$(document).ready(function() {
tw_attach_data_link_clicks(window.bpub.queue_web_services_base,
window.bpub.current_user);
});
// This handles automatically saving a field. Stick an attribute on
// an input, and when it changes this will automatically store it to
// localstorage. When the page is loaded, then we update the field
// with the data from local storage
$(document).ready(function() {
});
Here is my jquery.float plugin:
// @preserve jQuery.floatThead 1.2.12 - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2015 Misha Koryak
// @license MIT
/* @author Misha Koryak
*
*
*
*
*/
(function( $ ) {
/**
provides a default config object. You can modify this after including this script if you want to change the init defaults
@type {Object}
/
$.floatThead = $.floatThead || {};
$.floatThead.defaults = {
cellTag: null, // DEPRECATED - use headerCellSelector instead
headerCellSelector: 'tr:visible:first>:visible', //thead cells are this.
zIndex: 1001, //zindex of the floating thead (actually a container div)
debounceResizeMs: 10, //Deprecated!
useAbsolutePositioning: true, //if set to NULL - defaults: has scrollContainer=true, doesn't have scrollContainer=false
scrollingTop: 0, //String or function($table) - offset from top of window where the header should not pass above
scrollingBottom: 0, //String or function($table) - offset from the bottom of the table where the header should stop scrolling
scrollContainer: function($table){
return $([]); //if the table has horizontal scroll bars then this is the container that has overflow:auto and causes those scroll bars
},
getSizingRow: function($table, $cols, $fthCells){ // this is only called when using IE,
// override it if the first row of the table is going to contain colgroups (any cell spans greater than one col)
// it should return a jquery object containing a wrapped set of table cells comprising a row that contains no col spans and is visible
return $table.find('tbody tr:visible:first>*:visible');
},
floatTableClass: 'floatThead-table',
floatWrapperClass: 'floatThead-wrapper',
floatContainerClass: 'floatThead-container',
copyTableClass: true, //copy 'class' attribute from table into the floated table so that the styles match.
enableAria: false, //will copy header text from the floated header back into the table for screen readers. Might cause the css styling to be off. beware!
autoReflow: false, //(undocumented) - use MutationObserver api to reflow automatically when internal table DOM changes
debug: false //print possible issues (that don't prevent script loading) to console, if console exists.
};
var util = window._;
var canObserveMutations = typeof MutationObserver !== 'undefined';
//browser stuff
var ieVersion = function(){for(var a=3,b=document.createElement("b"),c=b.all||[];a = 1+a,b.innerHTML="",c[0];);return 4<a?a:document.documentMode}();
var isFF = /Gecko//.test(navigator.userAgent);
var isWebkit = /WebKit//.test(navigator.userAgent);
//safari 7 (and perhaps others) reports table width to be parent container's width if max-width is set on table. see: Safari Bug - max-width:100% and tiny viewport #108$test = $ ('
var isTableWidthBug = function(){
if(isWebkit) {
var
$("body").append($test);
var ret = ($test.find("table").width() == 0);
$test.remove();
return ret;
}
return false;
};
var createElements = !isFF && !ieVersion; //FF can read width from elements, but webkit cannot
var$window = $ (window);
/**
@param debounceMs
@param cb
*/
function windowResize(debounceMs, eventName, cb){
if(ieVersion == 8){ //ie8 is crap: ie8 feedback loop in resize() #65
var winWidth = $window.width();
var debouncedCb = util.debounce(function(){
var winWidthNew = $window.width();
if(winWidth != winWidthNew){
winWidth = winWidthNew;
cb();
}
}, debounceMs);
$window.on(eventName, debouncedCb);
} else {
$window.on(eventName, util.debounce(cb, debounceMs));
}
}
function debug(str){
window && window.console && window.console.log && window.console.log("jQuery.floatThead: " + str);
}
//returns fractional pixel widths
function getOffsetWidth(el) {
var rect = el.getBoundingClientRect();
return rect.width || rect.right - rect.left;
}
/**
try to calculate the scrollbar width for your browser/os
@return {Number}
/
function scrollbarWidth() {
var $div = $( //borrowed from anti-scroll
'
+ '
);
$('body').append($div);
var w1 = $div.innerWidth();
var w2 = $('div', $div).innerWidth();
$div.remove();
return w1 - w2;
}
/*
Check if a given table has been datatableized (http://datatables.net)
@param $table
@return {Boolean}
*/
function isDatatable($table){
if($table.dataTableSettings){
for(var i = 0; i < $table.dataTableSettings.length; i++){
var table = $table.dataTableSettings[i].nTable;
if($table[0] == table){
return true;
}
}
}
return false;
}
function tableWidth($table, $fthCells, isOuter){
// see: Safari Bug - max-width:100% and tiny viewport #108
var fn = isOuter ? "outerWidth": "width";
if(isTableWidthBug && $table.css("max-width")){
var w = 0;
if(isOuter) {
w += parseInt($table.css("borderLeft"), 10);
w += parseInt($table.css("borderRight"), 10);
}
for(var i=0; i < $fthCells.length; i++){
w += $fthCells.get(i).offsetWidth;
}
return w;
} else {
return $tablefn;
}
}
$.fn.floatThead = function(map){
map = map || {};
if(!util){ //may have been included after the script? lets try to grab it again.
util = window._ || $.floatThead._;
if(!util){
throw new Error("jquery.floatThead-slim.js requires underscore. You should use the non-lite version since you do not have underscore.");
}
}
if(ieVersion < 8){
return this; //no more crappy browser support.
}
var mObs = null; //mutation observer lives in here if we can use it / make it
if(util.isFunction(isTableWidthBug)) {
isTableWidthBug = isTableWidthBug();
}
if(util.isString(map)){$this = $ (this);$.extend({}, $ .floatThead.defaults || {}, map);
var command = map;
var ret = this;
this.filter('table').each(function(){
var
var opts = $this.data('floatThead-lazy');
if(opts){
$this.floatThead(opts);
}
var obj = $this.data('floatThead-attached');
if(obj && util.isFunction(obj[command])){
var r = objcommand;
if(typeof r !== 'undefined'){
ret = r;
}
}
});
return ret;
}
var opts =
$.each(map, function(key, val){
if((!(key in $.floatThead.defaults)) && opts.debug){
debug("Used ["+key+"] key to init plugin, but that param is not an option for the plugin. Valid options are: "+ (util.keys($.floatThead.defaults)).join(', '));
}
});
if(opts.debug){
var v = $.fn.jquery.split(".");
if(parseInt(v[0], 10) == 1 && parseInt(v[1], 10) <= 7){
debug("jQuery version "+$.fn.jquery+" detected! This plugin supports 1.8 or better, or 1.7.x with jQuery UI 1.8.24 -> http://jqueryui.com/resources/download/jquery-ui-1.8.24.zip")
}
}
this.filter(':not(.'+opts.floatTableClass+')').each(function(){$table = $ (this);
var floatTheadId = util.uniqueId();
var
if($table.data('floatThead-attached')){
return true; //continue the each loop
}
if(!$table.is('table')){
throw new Error('jQuery.floatThead must be run on a table element. ex: $("table").floatThead();');
}
canObserveMutations = opts.autoReflow && canObserveMutations; //option defaults to false!
var $header = $table.children('thead:first');
var $tbody = $table.children('tbody:first');
if($header.length == 0 || $tbody.length == 0){
$table.data('floatThead-lazy', opts);
$table.one('reflow', function(){
$table.floatThead(opts);
});
return;
}
if($table.data('floatThead-lazy')){
$table.unbind("reflow");
}
$table.data('floatThead-lazy', false);
});
return this;
};
})(jQuery);
/* jQuery.floatThead.utils - http://mkoryak.github.io/floatThead/ - Copyright (c) 2012 - 2014 Misha Koryak
*
*
*
*/
(function($){
$.floatThead._ = window._ || (function(){
var that = {};
var hasOwnProperty = Object.prototype.hasOwnProperty, isThings = ['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'];
that.has = function(obj, key) {
return hasOwnProperty.call(obj, key);
};
that.keys = function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = [];
for (var key in obj) if (that.has(obj, key)) keys.push(key);
return keys;
};
var idCounter = 0;
that.uniqueId = function(prefix) {
var id = ++idCounter + '';
return prefix ? prefix + id : id;
};
$.each(isThings, function(){
var name = this;
that['is' + name] = function(obj) {
return Object.prototype.toString.call(obj) == '[object ' + name + ']';
};
});
that.debounce = function(func, wait, immediate) {
var timeout, args, context, timestamp, result;
return function() {
context = this;
args = arguments;
timestamp = new Date();
var later = function() {
var last = (new Date()) - timestamp;
if (last < wait) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) result = func.apply(context, args);
}
};
var callNow = immediate && !timeout;
if (!timeout) {
timeout = setTimeout(later, wait);
}
if (callNow) result = func.apply(context, args);
return result;
};
};
return that;
})();
})(jQuery);
It worked for me JSfiddle. Here is the link for that: http://jsfiddle.net/833eLyod/18/
The text was updated successfully, but these errors were encountered: