Manipulating the Koha patron checkouts table 1


In Koha 3.16.03, the checkouts table was changed from a table where the data was loaded before displaying the checkout screen to an Ajax DataTable where the checkouts are loaded *after* the circulation screen is loaded. Why did this change? The answer is simple; speed!

The circulation screen takes time to load, and each checkout adds a bit more time to that loading process. A patron with dozens of checked out items will take much longer to load than a patron with only one or two. By delaying this processing, Koha’s checkout function is now far more responsive!

However, there are some negative consequences to this. The primary one is that we can no longer manipulate the checkouts table with the JavaScript we could previously use in order to customize it in some ways. However, there is a solution! We can listen for an ‘event’ that tells us the DataTable of checkouts has loaded. At that point we can use the DataTables API to manipulate the table however we wish!

Here is one example. In this example, we are hiding all the data in the renewal column for items that were not checked out at the logged in branch. In effect, we are preventing a library for easily/accidentally renewing items from another library:

$( document ).ready(function() {
 $('#issues-table').on( 'init.dt', function () {
   logged_in_branch = $.trim( $(".navbar-inner .pull-right strong").html() );

   var rows = $("#issues-table").dataTable().fnGetNodes();
   for ( var i=0; i < rows.length; i++ ) {
     var checked_out_from = $(rows[i]).find("td:eq(4)").html();
     if ( checked_out_from != logged_in_branch ) {
       $(rows[i]).find("td:eq(8)").children().hide();
     }
   }
 });
});

The key point here is this:

$( document ).ready(function() {
 $('#issues-table').on( 'init.dt', function () {
   // At this point, we know the table exists and we can manipulate it!
 });
});

This is the most important part of the example. You can see the use of ‘init.dt’ for the id ‘issues-table’. This same code could be used with any other datatable in Koha simply by changed the ID used!

I hope this proves helpful to all the Koha hackers out there!


Leave a comment

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

One thought on “Manipulating the Koha patron checkouts table

  • Scott Merrill

    Thanks for the script. I previously had some columns hidden that broke with the data tables update and was able to fix it using this.

    I ran into a small problem copying the script. The < in the for loop above looks like it was encoded as < in the HTML.