An Extensive Examination of the PHP:DataGrid Component: Part 2
(Page 2 out of 2)By default PHP:DataGrid displays all the columns that are available in the data. This may not be what you want though, and most of the time you probably want to display only a few columns. To do this you must set the AutoGenerateColumns property to false, to tell PHP:DataGrid that you want to specify the columns that should be shown.
Once you've done that, you must specify some columns to display, otherwise nothing will be displayed. To do this, you're going to have to use a new tag - the Column tag.
A simple example of a column tag would be:
That's all that's necessary to display the title column. Of course, you can specifiy additional attributes, like HeaderText or FooterText, and it's possible to use styles. Below is an example of using custom columns:
If you run the code above, or view the live demo, you will notice that it only displays the three columns we specified, with the appropriate header text. The title and filename columns also have a custom item style. Combining all these techniques will allow you to customize your datagrid to your liking, and you can change almost every aspect.
Conclusion
Take a look at the first demo and compare it to what we have now. It certainly looks a lot better, and it's all done using HTML tags. We haven't written a single line of PHP code. Without PHP:DataGrid this wouldn't be possible, and it would have been much harder to get the same result.
What's in store for the next part? We're going to have a look at creating some interaction with our datagrids. For example, have a "More Details" button that shows more details, or firing a server-side event when a button is clicked. The full details will be in the next part!
Don't forget, you can buy PHP:DataGrid with a discount if you use our coupon code: phpit
Visit the PHP:DataGrid product page