setUniqueId(string $uniqueId)

The setUniqueId method is a useful tool to know for client side caching. This is the unique id that you give in order to cache some preferences such as per-page, ordering,... e.t.c. when the user refreshes the page or come back in after a while.

The syntax is simple, you just need to add a unique value (unique to the other tables)


By default the uniqueId is auto set by the hash of the URL so you don't have to. However there are cases that the URL is changing although we are referring to the same CRUD. In that case it is suggested to use the setUniqueId method.

Below you can find a full example:

$crud->setSubject('Customer', 'Customers');


return $crud->render();

There is not much to see at the bottom example, however you can check your localStorage and see the value of the 'customers_1234'. More specifically, if you are on chrome:

  1. At the example below press the header 'customerName' so you will order by name (and the cache will remember it!)
  2. Press right click anywhere at the page and press "Inspect"
  3. Now that the developers tools are open go to the tab "Application"
  4. At the left menu press localStorage and search for the website
  5. Now you can see that there is a value named 'gcrudInitialData_customers_1234'
  6. Now refresh the page and you will see that the browser "remembers" your last sorting