Modernizing With PHP Grid Tools

Print

This year being the 25th anniversary of the birth of our beloved IBM i, we thought it might be an appropriate time to get back to the topic of modernization. As those of you who have read any of our previous columns on this subject will know, we’re big fans of anything that will help maximize returns while minimizing effort. That means finding tools that help us get things up and running quickly.

Why do we feel this is so important? Because we’ve seen so many companies’ modernization efforts stumble at the starting line while their RPG team continues to try to select the “perfect” tool. We have a very simple mantra when it comes to modernization:

“The only thing you can do wrong is to do nothing.”

Don’t waste time trying to find the perfect tool—there isn’t one—and, more importantly, there never will be. You should certainly evaluate more than one tool before making a final decision, but for many, the pressures of daily work will cause that effort to move exceedingly slowly.

Start Small

What we often recommend to our clients is not to start by attempting a massive modernization of their existing applications, but rather “nibble away” around the edges to gain experience. For example, convert a few print reports to the Web. This is a great first Web project, and typically a relatively easy task with a high user satisfaction payback. For details of one approach to this task, check out our article “Webulating Printer Output Revisited.”

Another option is to use one of the free/low-cost tools available to give your users the new Web-based reporting they’ve requested. A good reason for taking this approach is that until you put something in front of the users they don’t know what to request! Once they have something to look at and play with they can begin to tell you what they really need. Otherwise all too often it becomes a case of the blind leading the blind. Trust us—your efforts will be much more productive if you start by taking baby steps.

Back in late 2011 we blogged about one tool that can help you to get started—Planet J’s WOW Community Edition.

In recent weeks we have also come across two new PHP-based tools that, with minimal work, can really be an eye opener for those in your organization who think IBM i can’t do this kind of thing. They are phpGrid and iDataGrid. The results produced by the two can be very similar, as the images you’ll see below will show you. But they work in very different ways.

phpGrid

phpGrid is a class library designed to be used in your own PHP applications. With absolutely minimal coding, it can produce highly usable Web pages that provide all of the bells and whistles Web users have come to expect—such as column sorting, resizing, export of results to Excel, etc. In keeping with most modern Web applications, it makes extensive use of JavaScript libraries to provide maximum flexibility in the user interface. In the case of phpGrid, the libraries used are the popular jQuery and jqGrid.

A quick look at the company’s website shows you that it has some pretty big-name clients ranging from Cisco to Bank of America and even the Government of Canada (Nice to see our tax dollars put to such good use!). The product comes in multiple versions each of which offers different capabilities. At the bottom end of the scale comes phpGrid Lite. This is the one we used for our examples. It’s free but has two significant restrictions. The free version can’t produce grids that provide editing capabilities and it can only use MySQL (i.e., ZendDbi) tables. Of course since we have the DB2 storage engine available to us, even this basic version can produce reports of DB2 data, but you should bear this limitation in mind. We should point out however that you can remove both of these restrictions by paying the massive sum of $195 (no, that’s not a mistype) for the Professional version, which includes six months of free updates and support.

So when we say “minimal coding” exactly what do we mean? Well is this “minimal” enough for you?

<?php
require_once("../conf.php");
$dg = new C_DataGrid("SELECT customerNumber, customerName, city, 
state, country from customers", "customerNumber");
$dg -> display();
?>

Figure 1 is the Web page it produces. We think you’ll agree that’s quite impressive for such a minimal amount of code.

Now we confess that we cheated just a little bit here. The code as shown would not have provided for exporting to Excel. To implement that required the addition of this line prior to the invocation of the display() method:

$dg -> enable_export(); 

One other thing you may notice is that while column sorting is implemented in this grid (witness the upward pointing arrow alongside the customerName column heading) the column headings themselves have defaulted to the column names in the customers table. This is easy to deal with by simply adding a few more calls to the appropriate methods. Figure 2 is another version of that same grid that adds additional functionality.


Print

The second version was achieved by simply adding this additional code to the script:

$dg -> set_row_color('yellow', 'lightgray', 'lightblue');
$dg -> set_col_title("customerNumber","Customer #");
$dg -> set_col_title("customerName", "Name");
$dg -> set_col_title("city", "City");
$dg -> set_col_title("state", "State");
$dg -> set_col_title("country", "Country");
$dg -> enable_search(true);

The first line sets the row colors to alternate (green bar paper, anyone?) and to highlight the current cursor position in yellow. The second and subsequent lines set the column headings. The last line is responsible for the filtering boxes that appear above each column. We have entered a value of “USA” into the country box and you can see the results.

Having used this product for a while now, we can see why it gets so many rave reviews from its users. As a prototyping tool, it’s really hard to beat and just the thing to help you and your users make decisions as to what you really need to develop for the longer term. Visit the company’s website to see working examples of many of the additional features the product provides.

phpGrid offers multiple pricing options ranging from free to $1,295 for the high-end version, which includes full source code. To see what you get for your money at the different levels, take a look at the company’s download page.

iDataGrid

iDataGrid provides similar capabilities but with three major differences:

  1. It supports DB2 out of the box. In fact, it was designed as an IBM i tool by former Zend staff who were instrumental in bringing PHP to the IBM i. It also supports MySQL, MSSQL and others. We’ve successfully used it with both DB2 and MySQL.
  2. You use a wizard interface to define the content of your application and it generates a PHP script to implement your specifications. Unlike some similar tools, it stores all of the choices you made in a separate database so the application can be regenerated at a later time should you wish to make changes. You can also directly modify the script, but of course you need to be aware that such changes will be lost if the application is regenerated. It would therefore be a good idea to isolate any such changes in include members thereby minimizing rework.
  3. Editing and other features that are only available in the for-fee versions of phpGrid are part of the basic free version of iDataGrid.

While iDataGrid is free of charge, the company does offer a service contract option which, in addition to technical support, also provides you with access to additional features such as their “Pro” options. Currently, this is priced at approximately $2,500 per year.

When you first connect to iDataGrid, you’re presented with the Pages Manager as shown in Figure 3. From this point, you can create a new page or edit an existing one either via the “Code” or “Wizard” option links.

Once pages are developed and tested, you can copy them anywhere you like, so don’t be concerned that users will have access to this interface; they won’t.

To produce the same basic application we showed you with phpGrid requires that we complete three sections of the wizard dialog. The first, shown in Figure 4, is the “Creating & Calling” section where we define the type of database we’re using along with the User Profile information. The second is the “Sorting & Paging” section where we specify whether we want paging built in, how many rows on a page and where the paging controls should appear. The third is the “VIEW Mode Settings” where we define the basic SQL query and identify the fields we want included in the grid. In our case, we opted to show all the selected fields. You can also select the width of the grid and whether you want a horizontal or vertical view with horizontal being the norm.

That’s all there is to it. The resulting Web page in Figure 5 is not bad for two minutes of work!

As you can see, even though we specified a page size of 20 rows, users can change this value if desired. They can also sort on any column, add new records, etc.

To enhance the page to a similar level to the second phpGrid example, we had to change settings in three other sections.

  1. “General” where we specified the page heading and also the export options. We also selected an alternative look and feel by requesting a different style sheet from the standard set.
  2. “Printing & Exporting” where we specified that we wanted the option to export the results in PDF, Excel and XML formats.
  3. “Filtering” where we specified the columns that we wanted to be able to use for filtering and the criteria to be applied. Unlike phpGrid, iDataGrid requires that you specify each column you want to filter. While that’s more work, the number of selection options available is far more comprehensive. If you look at Figure 6, you’ll see that we opted to have the Name field as a text box and selected %like% as the operator which will search for the text we enter anywhere in the field. We also specified that Country should be a pull-down list built from the values present in the database.

Once those options had been specified, we recreated the page and ran it, as shown in Figure 7. To demonstrate the country filtering, we captured it in action with the pull-down deployed. You can also see the new color scheme and the icons for the export options we selected.

Hero Status

With both tools, our first live pages were produced within minutes of installing the product. In the case of phpGrid, this involved nothing more than uploading the source files to the document root on our Apache server. In the case of iDataGrid, it involved uploading and restoring a save file and executing an install command.

Neither tool is perfect, but either can certainly save you a lot of time and effort and we’ll be making use of both in our own applications. Check them out and take the firsts step to hero status with your users.