Skip to content

Use it with a Java or Node server ​

Since 1.8.0

The three samples are in the samples folder of the downloaded zip (maxgrid-<version>-all.zip). The CDN version and SRI hashes in the pages match the version of that zip. The pages load the grid with script tags as in Use it with jQuery (the grid also works without jQuery).

Whether the server is Java (Spring Boot, JSP, eGovFrame style) or Node, it works the same way. The grid only runs in the browser and talks to the server through one JSON format.

Server mode: the server handles paging, sort and filter ​

With many rows the server cuts the pages. The grid sends page number, size, sort and filter, and receives { rows, totalRows }.

js
pagination: {
  mode: 'server',
  pageSize: 20,
  loadPage: function (q) {
    var p = new URLSearchParams({ page: q.page, pageSize: q.pageSize });
    if (q.sort.length) p.set('sort', JSON.stringify(q.sort));
    if (q.filter) p.set('filter', JSON.stringify(q.filter));
    return fetch('api/staff?' + p, { signal: q.signal }).then(function (r) { return r.json(); });
  },
}

The server API (address, query, response, errors) is written once in the server-mode section of Pagination. The samples handle operators such as contains, equals, between, in and all/any groups.

Saving and xlsx ​

  • Batch save: set saveMode: 'batch' and call api.save() from a save button. saveHandler posts api.getChanges() to POST /api/staff/batch; the server answers { ok: [...], failed: [...] }. Values the server decides, such as a new row id, go back in ok as { key, row } (Batch save).
  • xlsx: to build it in the browser use downloadXlsx (Export). When the server must build it (permissions, huge data), send the current sort and filter as the query to GET /api/staff.xlsx. The samples write a minimal xlsx without a library; use a library such as Apache POI when you need styles and formulas.

The three samples ​

SampleServerIn one line
node-expressNode 20+, ExpressOne handler (api.mjs) that Express wraps thinly
spring-boot-thymeleafJava 17, Spring Boot 3.5StaffController only does HTTP, the rules are in StaffData, the page is Thymeleaf
jsp-egovJava 17, servlet + JSPOne servlet and index.jsp, no framework. For eGovFrame 4.x switch to javax.servlet

Running them ​

SampleRunAddress
node-expresscd samples/node-express && npm install && npm starthttp://localhost:3000
spring-boot-thymeleafcd samples/spring-boot-thymeleaf && mvn spring-boot:runhttp://localhost:8080
jsp-egovcd samples/jsp-egov && mvn package, then put target/*.war on Tomcat 10 or newerthe Tomcat address (deployed at /)

Change the port with the environment variable PORT (Node, Spring Boot). Put the license key in MAXGRID_LICENSE_KEY.

Checking everything at once ​

Without starting servers yourself, this builds the three samples, starts them on free ports, and checks the server API (seven items), the first page, that the license key is written into the page safely, and that in a browser the grid is drawn and sorting goes to the server.

bash
node samples/smoke.mjs                  # Node, Spring Boot and JSP
node samples/smoke.mjs --only node     # one of them (node, spring, jsp)

The Java samples need JDK 17 or newer and Maven (they are skipped without them). The browser step uses Playwright's Chromium (--no-browser leaves it out). The version and SRI hash the sample pages load from the CDN are written in the pages' script tags. When you move to a new version, change both together with the hash that came with the release.

All load the bundle from the CDN with an exact version and SRI. The license key lives in the server environment variable MAXGRID_LICENSE_KEY and is written into the page. Never put a key in source control or a JS file. Without a key an evaluation mark appears and every feature works (License).

Swap in your database

The sorting, filtering and saving rules are collected in StaffData (Java) and staff.mjs (Node). Replace them with JPA or MyBatis queries that keep the same input and output; the page needs no change.