0

I've asked this question before, but I think I've figured what the problem may be.

I have a page, which holds a table div. I use an AJAX call to get a table (not a partial, its just another table.html.erb with its own method in its controller).

In this table.html.erb, I followed Kaminari guidelines for AJAX pagination. Why use another AJAX call to paginate if I already have one?

Because, if I click on the pagination link, Kaminari paginates the link into the entire page, instead of inside the div.

Hence, why I am using a partial within an AJAX called table div. However, I cannot go to the next page now or any other page. In my console, the correct queries are being made. When I actually right-click and open the page in a separate tab, I can change links (Only if I disable the rendering of the application and bootstrap layout).

One reason was just mentioned, the other I suspect, is that since I have a partial within another AJAX called view, the table actually won't update if I don't make an AJAX call to the table after I click another page for Kaminari.

To summarize:

index.html.erb

<div id="table"><div>

<script> $.ajax({
        url: "http://localhost:3000/request/table",
        type: "GET",
        success: function(data) {
            $("#table").html(data);
        }
    });
</script>

show.html.erb

<table id="table">
    <thead>
        <tr>
            <th> Boop! </th>
        </tr>
    </thead>
    <tbody id="items">
    <% render @items %>
    </tbody>
    <div id="paginator">
        <%=  paginate @items, :remote => true %>
        <%= page_entries_info @items, :remote => true %>
    </div>
 </table>

<script>
    $('#analytics').html('<%= escape_javascript render(@items) %>');
    $('#paginator').html('<%= escape_javascript(paginate(@items, :remote => true).to_s) %>');
</script>

partial: _item.html.erb

<tr>
<td> item.name </td>
<td> item.date </td>
</tr>

In summary,

I can open the pagination links (1,2,3,... Next, Previous) in a separate tab or as a full page url. I cannot update table by clicking pagination links.

user1002563
  • 335
  • 1
  • 4
  • 17

1 Answers1

0

When you right-click and open the links, it's requesting a "html" response.

When you click on :remote => true links, it requests a "js" response....

You will need to create a (I assume it's "index" action?) index.js.erb view with the Javascript to "update" the #table with the new data.

omarvelous
  • 2,774
  • 14
  • 18
  • I sort of see what you are saying. Using Chrome's inspector, when I click on the links, there are definitely http requests going out. The response is also the appropriate page. So it is definitely the html just not updating. – user1002563 Jan 29 '13 at 20:43
  • You have to tell the browser using js how to update the html. – omarvelous Jan 29 '13 at 22:13