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

rescue dataTable properties #409

Closed
ghost opened this issue Jun 13, 2016 · 17 comments
Closed

rescue dataTable properties #409

ghost opened this issue Jun 13, 2016 · 17 comments
Milestone

Comments

@ghost
Copy link

ghost commented Jun 13, 2016

On paginated datatables, whenever the page is reloaded, all options of pagination and ordering get lost. This is weird, as when you work with a table and have to leave the page for another issue, you have to fiddle the old options again when you come back.

How about an attribute to the dataTable tag that keeps all current dataTable options? This could be a java bean so that all options may be made persistent by jsf itself. The update of the java bean could be done automatically by every change in java script (using ajax of course). I'd need such a feature and could implement it myself, but I wonder if it would be possible to do that in a common way so that this could get back to the master branch...

Let me give you an example of my understanding of this idea:

<b:dataTable ... storage="#{myBean}" pageLength="#{myBean.pageLength}">...</b:dataTable>

MyBean must be an implementation of IDataTableProperty (could also be an abstract class):

public interface IDataTableProperty {
  public void setPageLength(Integer pageLength);
  public Integer getPageLength();
  public void setOrdering(String ordering);
  ...
}

And on every javascript change of the table's display nature, in

table.columns().every(function(){
...
}

could be bound an ajax call to update myBean.

The benefit would be that I could just take myBean, put it into my session and make it persistent if I want to keep it alive over sessions (for example as json object into a postgreSQL db).

@stephanrauh stephanrauh added this to the v1.0.0 milestone Jun 13, 2016
@stephanrauh
Copy link
Collaborator

Whow! Sounds like a good idea. Let's collect a list of properties to be saved:

  • Current page
  • Pagination page length
  • Sort order

Anything else?

@ghost
Copy link
Author

ghost commented Jun 14, 2016

yes, the filter field should also be added

btw. you added this to v1.0.0 as milestone; I need this feature a bit earlier. How about a new branch on current stable release 0.8.6 to add this changes?

@zhedar
Copy link
Collaborator

zhedar commented Jun 14, 2016

Currently the team's time is sparse, therefore we cannot promise to deliver a fast implementation, but if you want to try this yourself, we could also get this into 0.9.0 .

@stephanrauh
Copy link
Collaborator

@jottyfan I'd love to implement your feature in 0.9.0, but chances are we publish this version this weekend. That means it's too risky to add a major feature in such a time frame. What we can talk about, is publishing another intermediate version before 1.0. But I doubt you need the feature that fast: 1.0 is due just before the JavaOne conference. Even so, you could start with the developer preview.

And, like @zhedar said, you can speed up thing be sending us a pull request. Interested?

Best regards,
Stephan

@ghost
Copy link
Author

ghost commented Jun 14, 2016

Ok, I didn't know about your release plans. In this case, I'd be very glad to have this extension added in a 0.9.X branch, maybe in a snapshot version. I'll try to find a way to implement this on the 0.9.0 branch as soon as I can find some time. If it works the way I hope, I will make a pull request here.

@ghost
Copy link
Author

ghost commented Jun 15, 2016

Doing so (as mentioned), I'm stuck on generating the ajax call to bind the table's configuration variables to the bean. This is the point where I think one of you developers could help me with an example for understanding bootsfaces ajax.

What I have is:
in DataTableRenderer.encodeEnd(...), I add this javascript code to the respone writer:

...
if (propertyBean != null) {
  rw.writeText("table.on('drawCallback', function(settings){" + 
               "  updateDatatableProperties(table, settings);" + 
               "});", null);
}
//# End enclosure
rw.writeText("} );", null );
rw.endElement("script");

Now that I need is the implementation of updateDatatableProperties to update the propertyBean with values from settings. This would be done by bootsfaces ajax, but I've got too less understanding.

propertyBean is an instance of ADataTablePropertyBean:

public abstract class ADataTablePropertyBean {
    private Integer pageLength;
    private Integer currentPage;
    private String searchTerm;
    private String orderString;

    public ADataTablePropertyBean(Integer pageLength, Integer currentPage, String searchTerm, String orderString) {
        this.pageLength = pageLength;
        this.currentPage = currentPage;
        this.searchTerm = searchTerm;
        this.orderString = orderString;
    }
 + getter/setter
}

The javascript function drawCallback is given by https://datatables.net/reference/option/drawCallback itself, and I suggest settings to contain the current values we're interested of.
So instead of forcing the user to create a updateDatatableProperties java script function to bind his bean to the settings, I'd like this to be done by bootsfaces, but I don't currently know how. Any help is welcome.

I'd like to push my current developement state, but github doesn't allow me to create a new branch, I get this error: git-receive-pack not permitted. Seems that I have not enough rights for that...

@stephanrauh
Copy link
Collaborator

As for the branch: create your own branch by clicking on the "fork" button at the top of this page. This creates a copy of BootsFaces in your own repository, and you've got full write access (because it is your own repository).

@stephanrauh
Copy link
Collaborator

The encodeEnd()-approach sounds promising. You're on the right track. I suggest you store the settings as a Json-object in a hidden field in front of the table. I've used a similar approach with b:tabView and b:gyroscope. Storing the information in a hidden field with a name automatically causes the value to be sent to the server with each AJAX or non-AJAX request.

The second part is to read the value of the hidden field on the server. This is done in the decode() method. Once again, the GyroscopeRenderer and the TabViewRenderer are good starting points to learn how to do it.

@ghost
Copy link
Author

ghost commented Jun 16, 2016

So I created a fork, the new repo is now available on https://github.com/jottyfan/BootsFaces-OSP and all changes are done in branch datatableoptions.

I wonder how you will be able to get the changes back to your base repo, but this may be one of the next steps when all changes are included.

Thanks for your hint about the fork, I didn't know that.

@zhedar
Copy link
Collaborator

zhedar commented Jun 16, 2016

@jottyfan Getting the changes back, as in merging, happens via Pull Requests.
You should be prompted to create one, if you've got unmerged changes in your fork and e.g. enter the the original repository (e.g. here).

@ghost
Copy link
Author

ghost commented Jun 16, 2016

ok, so when I'm finished in developement, I merge my branch to my forked master. Then, I do a pull request to the fork source?

@zhedar
Copy link
Collaborator

zhedar commented Jun 16, 2016

Actually the pull request already does a merge tiself, so you don't have to do that before.

It's also possible to open a PR before you finished everything, it will get us the possibility to review your changes and discuss them, so you don't have to wait for your last adjustments to open one, if you push to a branch you opened a PR on, it will also be added to the PR.

@ghost
Copy link
Author

ghost commented Jun 16, 2016

Ok, that's easier, nice. How can I mark my pull request to be a "do not yet pull, just watch it" request? I don't want this code to be included into the main branch until it is good enough...

If I just pull the branch, who gives me a guarantee not to merge this?

@zhedar
Copy link
Collaborator

zhedar commented Jun 16, 2016

It should suffice to put it into the description, then edit it out and comment again, when you're done. Atleast that's what I did.

If I just pull the branch, who gives me a guarantee not to merge this?

You probably shouldn't have to worry, no one will merge a PR without having a closer look at it.

@ghost
Copy link
Author

ghost commented Jun 16, 2016

ok, created a pull request

@ghost
Copy link
Author

ghost commented Jun 17, 2016

again one question

if you look at the pull request, you can find a comment in DataTableRenderer's encodeBegin method in line 133 - this is where I put the hidden input field for storing the javascript values. Now this question is simple: how do I implement a <f:ajax /> call for my dataTable.onUpdateProperyBean here? I'm convinced there is an elegant solution, but I'm still not familiar enough with this.

Maybe you have another example for me?

@ghost
Copy link
Author

ghost commented Jun 22, 2016

this feature is still being integrated in the main branch, therefore I close this issue.

@ghost ghost closed this as completed Jun 22, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants