sfGridPlugin - 0.1.1

An extensible grid subframework allowing the display of data from various data sources in grids using various formatters

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
sfGridPlugin 0.1.1alpha for sf 1.2sf 1.1 MIT
Plugin image
10
users
Sign-in
to change
your status

This plugin contains a grid subframework that allows to read various data sources in a unified way. These data sources can be rendered in a customizable grid with a custom formatter. The code of this plugin will eventually become bundled with symfony 1.3.

Currently, arrays and Doctrine tables can be used as data sources. Propel, XML and CSV are planned for the final version Only a HTML formatter is currently supported. A raw text formatter and an XML formatter are planned for the final version.

THIS PLUGIN IS IN VERY EARLY ALPHA STAGES AND IS NOT RECOMMENDED FOR PRODUCTION USE.

Please NOTE: this plugin has been updated, and now depends on the sfDataSourcePlugin

Introduction

This plugin contains a grid subframework that allows to read various data sources in a unified way. These data sources will be rendered in a customizable grid with a custom formatter.

Currently a HTMLand text formatter are supported. The release of the JSON formatter is expected soon.

Howto

A quick guide to show how to start using the sfGrid.

First install the sfDataSourcePlugin.

In this example I will show the usage with the help of the sfDataSourcePropel class, however sfDataSourceDoctrine and sfDataSourceArray are available as well.

The DataSource can be provided to the sfGrid in order to render the data to the screen.

A slightly more specialised version of the sfGrid, the sfWebGrid that can be bond to the webRequest, will be used in order to automatically process the interaction with the grid (the sorting and paging). Before you can render your grid in a template you first have to provide the columns available from your sfDataSource to the grid. Besides you probably want to define the title for the columns in your grid.

For the following schema.yml:

propel:
  city:
    id:
    name:       varchar(255)
    country_id:
    created_at:
  country:
    id:
    name:      varchar(255)
    created_at:

Lets see that in action.class.php:

// get a dataSource
$dataSource = new sfDataSourcePropel('City');
 
// create a grid bound to your dataSource
$this->grid = new sfWebGrid($dataSource);
// and bind in to the request to handle interaction
$this->grid->bind($request);
 
// sorting is disabled by default, so enable it to all columns
$this->grid->setSortable(sfGrid::ALL);
// and define the default sort-order
// (in this case the sfDataSourcePropel knows how to handle the relation, and will automatically perform a join!) 
$this->grid->setDefaultSort('Country.Name', sfGrid::ASC);
 
// define the columns you want to see
$this->grid->setColumns(array(
  'Country.Name',
  'Name'
));
 
// and overrule their titles
$this->grid->setColumnTitles(array(
  'Country.Name' => 'Country',
  'Name'                 => 'City'
)); 

And in your template enter:

<table>
<?php 
  $grid = $sf_data->getRaw('grid');
  echo $grid->__toString();
?>
</table>

The definition of columns in your grid is relative to your base object in your datasource. If you request related columns, from for example a country, the datasourcePropel will automatically perform a join on the album and hydrates this object as well. For Doctrine I haven't developed this yet, so maybe someone can write a behavior to support this as well (I am happy to help you with developping this, although short on time...), or you should setup your Doctrine-Query before providing it to the dataSource.

Todo:

Add an example CSS show more extensive examples

Note

The sfDataSourcePlugin is required for the sfGridPlugin.

License

see LICENSE file

Developers

Name Status Email
gravatar Bernhard Schussek lead moc.liamg <<ta>> kessuhcsb

License

Show source

Copyright (c) 2009 Bernhard Schussek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.