Skip to content
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

Query string keeps getting bigger ic-get-from / ic-current-url #315

Closed
etrokal opened this issue Mar 31, 2020 · 1 comment
Closed

Query string keeps getting bigger ic-get-from / ic-current-url #315

etrokal opened this issue Mar 31, 2020 · 1 comment

Comments

@etrokal
Copy link

etrokal commented Mar 31, 2020

Hello all. I started learning about Intercooler last week. I have a few doubts that I didn't find an answer to elsewhere. I'm trying to convert a pure HTML datatable to use Intercooler and even though it appears to be working, I'm experiencing an odd behavior. Every time a click on the table header, which contains link to order the data by the column names, the URL of the page gets bigger.

The view code is big, so I'll try to show only the relevant parts. This is my header code:

<tr>
    @foreach ($header as $key => $value)
    <td>
        @if($params['orderBy'] === $key)
        @php
        $url = request()->fullUrlWithQuery(['orderAsc' => (int) !$params['orderAsc']]);
        @endphp
        <a href="{{$url}}" ic-target="div.datatable" ic-select-from-response="div.datatable">
            {{$value}}
            @if($params['orderAsc'])
            <i class="fas fa-angle-up"></i>
            @else
            <i class="fas fa-angle-down"></i>
            @endif
        </a>
        @else
        @php
        $url = request()->fullUrlWithQuery(['orderBy' => $key, 'orderAsc' => 1]);
        @endphp
        <a href="{{$url}}" ic-target="div.datatable" ic-select-from-response="div.datatable">{{$value}}</a>
        @endif
    </td>
    @endforeach

    @if($addActionColumn)
    <td>{{$actionColumnCaption ?? ''}}</td>
    @endif
</tr>

This is a Laravel blade component. What I'm doing here is making each header a link that contains query parameters that refer to all parameters necessary to query the database for the results to be shown in the current page. So, the links all contain the following parameters: offset, limit, orderBy and orderAsc. By using the method fullUrlWithQuery in Laravel, I'm able to create a URL with all current query parameters changing only those provided in the array. In case the parameters provided were not present, they are added.

In my main component I have this tag:

<div ic-global-include="#limit,#filter" class="datatable" ic-enhance="true">
...

I also have a form with these fields to filter and change the number of results:

<select id="datatable-limit" name="limit" class="form-control" form="form-datatable" id="limit" ic-get-from="{{request()->fullUrlWithQuery([])}}" ic-target="div.datatable" ic-select-from-response="div.datatable">
    @foreach([10, 15, 30, 50, 100] as $qt)
    <option {{$params['limit'] == $qt ? 'selected' : ''}}>{{$qt}}</option>
     @endforeach
</select>

. . . 

<input id="filter" type="text" name="filter" class="form-control" placeholder="Filtrar Registros" value="{{$params['filter']}}" form="form-datatable" ic-get-from="{{request()->fullUrlWithQuery([])}}" ic-target="div.datatable" ic-select-from-response="div.datatable" ic-trigger-on="input" ic-trigger-delay="1000">

At first, everything works. But after a few clicks on the links from my table header this is my request URL. The URL keeps growing after each click, to the point that it corrupts and after that I only receive 404 errors.

I think it has something to do with the ic-current-url parameter, that is being added automatically to my URL, and it includes itself. So after each click the URL gets bigger.

@etrokal etrokal changed the title Query string keeps getting bigger ic-get-from / ic-curreent-url Query string keeps getting bigger ic-get-from / ic-current-url Mar 31, 2020
@etrokal
Copy link
Author

etrokal commented Apr 1, 2020

Solved the problem of the links by creating my own URL generating function. On the form, I added hidden fields containing all parameters as well.

@etrokal etrokal closed this as completed Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant