-
Notifications
You must be signed in to change notification settings - Fork 512
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
Comments
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 |
Adding a call to pipe from the postlink function in the stPipe directive would be a good way to achieve this, no? |
could be, not sure of any side effect though. Is that really big deal to get the first chunk of data from you controller :) ? |
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... |
Got your point, I'll try to have a look |
In what I tried, there is a conflict with pagination. |
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. |
Sorry if I was not clear, but this is not related to what you are saying. 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. |
Why is this closed? This sounds like pretty blatant issues. I've been looking for an alternative just because of this. |
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). Laurent R |
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. |
Hi, Static data and pagination is working which explained on http://lorenzofox3.github.io/smart-table-website/#section-pagination Please advise. |
Hi, regards |
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 |
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 <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> |
Hi, |
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. |
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 |
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. |
@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. |
@bassemBMI hi, can you explain me the detail? |
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
The text was updated successfully, but these errors were encountered: