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

datatable pagination with ajax data source #754

Open
joch40 opened this issue Sep 11, 2023 · 8 comments
Open

datatable pagination with ajax data source #754

joch40 opened this issue Sep 11, 2023 · 8 comments

Comments

@joch40
Copy link

joch40 commented Sep 11, 2023

Hi,

really good stuff, but with nearly no documentation (also in the api) it is very hard to adjust for own needs.

After some fight I got all the examples to work and to adjust to my data model.

It seems to me that the Ajax-Call Back only works if you use the Ajax-Data provider like in the InfiniteScrollDemoPage as only with this way you can set the DT_RowId and with out this value been set the call back is always empty. No problem with that in general, but the only way to feed the Data into the DataTable via the option.ajax way seems to be to create a subclass of an AbstractVirtualScrollResourceReference. That works also but with this I am loosing the pagination. So all works but whatever parameter I set I only get one endless page.

  • Anybody any idea to get the pagination for the AbstractVirtualScrollResourceReference or
  • another way to feed the data to option.ajax or
  • to get the call-back working without using the option.ajax way?

Best

Janko

@martin-g
Copy link
Member

Sorry for not being very helpful but I created the integration with DataTables.net because another user needed it. I haven't used it since then ... That's 5+ years.

AbstractVirtualScrollResourceReference provides virtual scrolling, i.e. the pagination is done automatically by DataTables while the user scrolls the table contents.

About the non-virtual scrolling - the best way to get help is to create a quickstart application that demonstrates the issue.

@joch40
Copy link
Author

joch40 commented Sep 12, 2023 via email

@martin-g
Copy link
Member

Hi Janko!

Instead of sharing your project you could fork wicketstuff/core and modify the datatables-examples project to show the problem and then share with us a link to the the fork.

@joch40
Copy link
Author

joch40 commented Sep 14, 2023 via email

@martin-g
Copy link
Member

martin-g commented Sep 15, 2023

The problem in NewPage is that there is no id attribute on the <tr> elements. To add this attribute you could override org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable#newDataGridView() and org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable.DefaultDataGridView#newRowItem()
This is needed because you give an HTML <table> to DataTables and it enhances it. But if something is missing then DataTables cannot magically add it. You could use something like

options.rowId(new Json.RawValue("function(person) { console.log('person', person); return 'id_' + person.DT_RowId; }"))

but as will see in the browser console the person is the TR HTML element, so not really nice way to calculate it's id.

The FilmPage uses an impl of org.wicketstuff.datatables.virtualscroll.AbstractVirtualScrollResourceReference but this is not mandatory. You can use a custom ResourceReference that returns pages of JSON data but you will also need to remove .scroller(scrollerOptions) from the options. Please check https://datatables.net/manual/server-side for more details. DataTables JS widget will just make an Ajax call to the mounted Wicket ResRef to ask for the JSON array for specific page.

@joch40
Copy link
Author

joch40 commented Sep 15, 2023 via email

@martin-g
Copy link
Member

The row item is used to populate the ` element - https://github.com/apache/wicket/blob/de89eb6a2db7fd25ca164e383daee38fa1053448/wicket-extensions/src/main/java/org/apache/wicket/extensions/markup/html/repeater/data/table/DataTable.html#L25

So, you need something like:

 protected Item<Person> newRowItem(String id, int index, IModel<Person> model)  {
     Item<Person> row = new Item<>(id, index, model);
     row.add(AttributeModifier.replace("id", model.getObject().getRow_Id()));
     return row;
}

I didn't use an IDE so the code might have errors, but this is the idea.

@joch40
Copy link
Author

joch40 commented Sep 22, 2023 via email

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

2 participants