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

Initial ajax call to fill the table #242

Closed
cadilhac opened this issue Dec 3, 2014 · 21 comments
Closed

Initial ajax call to fill the table #242

cadilhac opened this issue Dec 3, 2014 · 21 comments

Comments

@cadilhac
Copy link

cadilhac commented Dec 3, 2014

I added the st-pipe attribute to my table, referencing my getData function. It is never called. Looking at your code, it seems that it is called only when sorting or searching. Since this is the function that fills the grid given the tableparams, why is it not called initially?

Thanks

@lorenzofox3
Copy link
Owner

Not exactly, it is called whenever the table state change (search, page, sort, etc) or whenever the datasource change (binding or size). so you have to explicitly make the first datasource binding

@cadilhac
Copy link
Author

cadilhac commented Dec 4, 2014

Adding a call to pipe from the postlink function in the stPipe directive would be a good way to achieve this, no?

@lorenzofox3
Copy link
Owner

could be, not sure of any side effect though. Is that really big deal to get the first chunk of data from you controller :) ?

@cadilhac
Copy link
Author

cadilhac commented Dec 4, 2014

A big deal, no. But I favor encapsulation. If a directive is dedicated to showing a table with ajax data, then it should do it by itself. I come from datatables and this is how it's done too. (though not angularjs). This helps reusability too. It will be used on many pages and it would be better if I can just plug the directive on a page and it works, providing that I also reuse a service that will get the data. My 2 cents...

@lorenzofox3
Copy link
Owner

Got your point, I'll try to have a look

@cadilhac
Copy link
Author

cadilhac commented Dec 4, 2014

In what I tried, there is a conflict with pagination.
First of all, if I add pagination markup to my HTML, then the pipe is called as I expected and I don't have to modify the stPipe directive.
If I don't add pagination markup, and I keep my postlink fix, pipe is called but pagination state has only the start property, not the number property.

@lorenzofox3
Copy link
Owner

Not sure to understand the problem, could you provide a running example as explained in the readme.md please. But the table can not guess what is your dataset on the server (size, etc), so if you use a custom pipe function, you need to set the pagination state in that function as explained #207 and #146 and in the chat.

@cadilhac
Copy link
Author

cadilhac commented Dec 4, 2014

Sorry if I was not clear, but this is not related to what you are saying.
Let me say it in other terms:

With your current code, if I get first chunk of data from my controller AND if I use the pagination directive, the custom pipe function is called TWICE (because slice is called at the end of the pagination directive). That's why I was saying that encapsulation is the way to go. The client should not have to wonder if he has to call the initial getData or not depending on whether pagination is used or not. The smarttable code should handle both cases internally.

Also I realize that I intervened here for the first time with a question. But I want to add that I really like your code (how it's possible to design the table in a declarative way in the markup) and that this will be a time saver for me. Many thanks for that. That said, I discover that it is not rock solid yet as far as ajax/custom pipe is involved. For example, if the user deletes a row (with a button I provide), paging is not updated and the data is not refreshed by ajax automatically. If the user deletes the last element of the set and it was the single row in the last page of the table, the table becomes blank and it doesn't go to the previous page. These are the kind of cases I will have to study and update your code accordingly.

@cyberwombat
Copy link

Why is this closed? This sounds like pretty blatant issues. I've been looking for an alternative just because of this.

@lorenzofox3
Copy link
Owner

Because, I still don't understand the issue and the author failed to provide a way to reproduce the issue and showed he won't make any effort to help anyway (#244).
Note there is a specific section "submitting an issue" on the readme which tries to give guidelines on how you could help us to investigate a particular issue.
You can have a look at the "pipe/ajax plugin" section on the documentation as a starter to reproduce the issue. But on this example it seems to work as expected,
regards,

Laurent R

@cyberwombat
Copy link

I see. I am not sure about his second issues as I kinda stopped using this at the first one. I do find it odd behavior that the tables will not display anything unless sort/search is called. I eventually figured out I had to make a separate call by looking at the source as well. (might add to docs - I never did figure out why your demo seems to show data intially while my copy and pasting of it failed to do so). But I understand it's a design preference thing. But +1 for having the tables handle initial data load in case you are thinking about it. Thanks.

@mehulcrest
Copy link

Hi,
I am facing issue like the same.
I have code what you have explained on http://lorenzofox3.github.io/smart-table-website/#section-pipe but initial call is not working and no data coming to screen. It is showing the search controls. nothing happens even I write anything in search controls.

Static data and pagination is working which explained on http://lorenzofox3.github.io/smart-table-website/#section-pagination

Please advise.

@lorenzofox3
Copy link
Owner

Hi,
Again, it is difficult to advise if you don't provide a way I could reproduce the issue. So please, set up a plunker or any kind of running example. Apparently there is a real issue, and it would be great to fix it, but as it is, I can't help much.

regards

@lorenzofox3 lorenzofox3 reopened this Feb 3, 2015
@lorenzofox3
Copy link
Owner

ok with bb19a57, the first call to pipe should be handled by the table. Note as mentioned @cadilhac if you were using the pagination directive, the table was kicked by itself and you should not had any problem. Now to prevent the pipe function to be called twice you'll have to set the initial pagination state in you pipe function:

function customPipe(tableState, ctrl){

//if you use the pagination directive make sure to set the initial pagination state to prevent a second initial //call from the pagination directive
tableState.pagination.number = table.pagination.number || 10;
tableState.pagination.start = table.pagination.start || 0;

//custom pipe logic

}

A bit hackish but I have not found better so far

@mehulcrest
Copy link

Hi,

My issue was that the service is not being called in this case.

Now functionality is working fine when we did some changes in view (html) file.

I have added one outer div with alias "ctrl" in ng-controller attribute like
ng-controller="pipeCtrl as ctrl"
and
I have replace "mc" with "ctrl"

<div ng-controller="pipeCtrl as ctrl">
<table class="table" st-pipe="ctrl.callServer" st-table="ctrl.displayed">
            <thead>
            <tr>
                <th st-sort="id">id</th>
                <th st-sort="name">name</th>
                <th st-sort="age">age</th>
                <th st-sort="saved">saved people</th>
            </tr>
            <tr>
                <th><input st-search="'id'"/></th>
                <th><input st-search="'name'"/></th>
                <th><input st-search="'age'"/></th>
                <th><input st-search="'saved'"/></th>
            </tr>
            </thead>
            <tbody ng-show="!ctrl.isLoading">
            <tr ng-repeat="row in ctrl.displayed">
                <td>{{row.id}}</td>
                <td>{{row.name}}</td>
                <td>{{row.age}}</td>
                <td>{{row.saved}}</td>
            </tr>
            </tbody>
            <tbody ng-show="ctrl.isLoading">
            <tr>
                <td colspan="4" class="text-center">Loading ... </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td class="text-center" st-pagination="" st-items-by-page="10" colspan="4">
                </td>
            </tr>
            </tfoot>
        </table>
</div>

@bassemBMI
Copy link

Hi,
To force the first load I used data-ng-init="ctrl.callServer(ctrl.tableState)" , it's work and display first 10 records but not the pagination !!
Note that I passed "ctrl.tableState" to callServer function to avoid undefined tableState error

@bassemBMI
Copy link

Finally I fixed it, I'm using requireJS and I defined datatable files inside the same controller, so my controller was loaded before datatable, after moving those files to be load with the application it works fine.

@arulmozhimanikandan
Copy link

I have a diffrent problem, in my situation i load the table on page load itself next will have post request for different functionality, this ajax post request reseting the table data. any one facing this sort of issue

@crajkumarbe
Copy link

Hi mehulcrest/lorenzofox3,

Can you please upload your working copy of "pipectrl" from the server? Share us the code in plnker or jsfiddle or upload the zip file and provide the URL to download?

I'm facing similar kind of problem, but unable to figure out what is breaking.

@jsgoupil
Copy link

@lorenzofox3 Hey, thanks for clarifying why this is getting two requests. I have been looking forever.

However, this is way too hackish to be mainstream with your awesome smart-table. People will hit this problem and will end up on this github issue. I had to read the entire thread to finally get that I had to have 2 custom lines. This should definitely be handled differently. Your code is also incorrect, the variable is wrong.

This issue should be mentioned on the main website documentation. It is so hackish that I do feel it will pollute your documentation though.

@Troland
Copy link

Troland commented Apr 26, 2016

@bassemBMI hi, can you explain me the detail?

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

9 participants