html table header is aligning properly

13 views
Skip to first unread message

rrrah...@gmail.com

unread,
Aug 24, 2015, 6:18:19 PM8/24/15
to KnockoutJS
I am using Jquery.floatThead to create a floating table header. It works for some of the view but not for all. I am using knockout java to build the table. I rendered a afterRender: showAfterRender in the table on my show.html.erb file in rails application. Here is my show.html.erb file:

<!-- note that file_list.js will change this -->
<% content_for :title, 'Q' %>

<%= render 'q/queue/top_bar' %>
<div id="queue-app">


  <!-- note that this requires a tabindex so it can fire key press
  events -->
  <table class="queue-display
                table-striped
                table-hover
                table-condensed
                table-bordered
                unselectable"
         tabindex="0">


    <thead>
      <tr>

        <th class="queue-row-filename">
          <i class="fa fa-sort"
             data-bind="click: function() { toggleSortBy('filename') }"></i>
          filename
        </th>

        <!-- ko foreach: columns -->
        <th data-bind="atrr: {'class': 'queue-row-' + $data}">
          <!-- ko if: $parent.isSortableColumn($data) -->
            <i class="fa fa-sort"
               data-bind="click: function() { $parent.toggleSortBy($data) }"></i>
          <!-- /ko -->

          <span data-bind="text: $data"></span>
          <span data-bind="if: $parent.isRemovableColumn($data)">
            <i class="fa fa-close"
               style="cursor: pointer;"
               data-bind="click: $parent.removeColumn">
            </i>
          </span>
        </th>
        <!-- /ko -->
      </tr>
    </thead>

    <tbody data-bind="foreach: {
                        data: visibleQueueFiles,
                        beforeRemove: hideQueueFileElement,
                        afterAdd: showQueueFileElement, 
                        afterRender: showAfterRender 
                      }">
      <tr data-bind="css: {
                       selectedFile: selected,
                       activeFile: $parent.activeQueueFile() == $data,
                    }, attr: {'data-queue-file' : $data.id() }">
        <td>
          <button type="button" class="btn btn-default btn-xs"
                  data-bind="click: editFile">
            Edit
          </button>


          <a data-bind="click: function() { showInViewer() }"
             class="btn btn-default btn-xs">View</a>

          <span
                data-bind="text: filename,
                           style: {
                           'display' : 'inline-block',
                           'text-decoration': moved() ? 'line-through' : ''
                           }
                           ">

          </span>


          <span data-bind="if: moved">
            Moved to <span data-bind="text: moved_to_qid"></span>
          </span>

          <span data-bind="if: owner">
            <i class="fa fa-lock"></i>
          </span>

          <span data-bind="if: isNew">
            <i class="fa fa-plus"
               title="File added to queue"></i>
          </span>


        </td>

        <!-- ko foreach: $parent.columns -->
        <td class="qid"
            data-bind="text: $parent.displayForColumn($data),
                       attr: { 'title' : $parent.titleForColumn($data) }">
        </td>
        <!-- /ko -->


      </tr>
    </tbody>

  </table>

  <script type="text/javascript">
    $(document).ready(function() {
      var app = new queue.App(<%= @queue_info.to_json.html_safe %>);

      app.run();

      window.queueApp = app;

    });
  </script>

  <%= render 'q/queue/view_modal' %>

  <copy-dialog params="queueViewModel: $root"></copy-dialog>
  <rename-dialog params="queueFiles: selectedQueueFiles"></rename-dialog>
  <print-preview-dialog params="queueViewModel: $root"></print-preview-dialog>

  <%= render 'q/queue/custom_queues_modal' %>

  <%= render 'q/queue/bottom_bar' %>


</div><!-- #queue-app -->

Here is my javascript function:

this.showAfterRender = function (elements, data) {


         setTimeout(function(){

         var $table = $('.queue-display');

         $table.floatThead({useAbsolutePositioning: false, autoReflow: true});

         $table.trigger('reflow');

        }, 1000);

         }

What am i doing wrong? Why doesn't the table header align for some of the table views.

I am also creating these tables dynamically through knockout. For some odd reason it works when re-sizing the window even just a little bit everything aligns properly.

Reply all
Reply to author
Forward
0 new messages