Gravatar for jlynch@sonusnet.com

Question by Jim Lynch, Jan 3, 2017 12:03 PM

Creating table from results

This is a follow-up to https://answers.coveo.com/questions/6659/creating-table-header-outside-a-underscore-template?sort=votes

While the proposed solution in the above answer works fairly well, I am still running into some alignment issues between the header row and the other rows. Therefore, I am trying to use <table> instead of successive <div> tags.

I know when the first result is processed and can create the <table> tag at that time. Is there a way to detect when the last result is processed so that I can add the </table> tag ?

Thanks Jim

Gravatar for jlynch@sonusnet.com

Comment by Jim Lynch, Jan 4, 2017 2:54 PM

I thought CoveoFieldTable was the answer but that only allows you to create a table of multiple rows from one result. I am looking for a way to create a table of multiple rows/multiple columns where each result will populate the columns. Then I plan to add sorting on a few of the columns.

Gravatar for jlynch@sonusnet.com

Comment by Jim Lynch, Jan 9, 2017 6:21 PM

I am able to create the table from the preprocessResults event handler by writing the HTML. Therefore, this question can be disregarded.

1 Reply
Gravatar for flguillemette@coveo.com

Answer by François Lachance-Guillemette, Jan 10, 2017 11:45 AM

There might be better ways to do this, but here is an idea:

You have access to the index variable inside a result template, so you could add a simple trick using this variable to detect if the current result is the last one shown.

<script class="result-template" type="text/underscore">
  <div>
      <% if(!loadedHeaderOnce) { loadedHeaderOnce=true; %>
        <div class="table-header">...</div>
      <% } %>
      <div class="table-row">...</div>
      <% if (index == (LAST RESULT LOGIC HERE) { %>
          <div class="table-footer">...</div>
      <% } %>
  </div>
</script>
Ask a question