Coder Social home page Coder Social logo

helpfulrobot / bigfork-supergroupedlist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bigfork/supergroupedlist

0.0 2.0 0.0 11 KB

An extension of SilverStripe’s GroupedList that supports traversing relations

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%

bigfork-supergroupedlist's Introduction

#SuperGroupedList# Build Status Latest Stable Version Total Downloads License

An extension of SilverStripe’s GroupedList that supports traversing relations.

Note: depending on your data, the same items may be output multiple times. For example if a product belongs to multiple categories, and you group by category title, then the product will show under each of the categories that it belongs to.

###Installation###

composer require bigfork/supergroupedlist ^1.0

Or download and extract to a folder named supergroupedlist in your document root.

###Usage###

Use exactly as you would use GroupedList, but with dot-notation to traverse relations:

public function GroupedProducts() {
	$products = Product::get();
	return SuperGroupedList::create($products);
}
<% loop $GroupedProducts.GroupedBy('Categories.Title') %>
	<h1>{$Title}</h1><!-- Category title -->
	<ul>
		<% loop $Children %>
			<li>{$Title}</li><!-- Product title -->
		<% end_loop %>
	</ul>
<% end_loop %>

You can traverse has_one, has_many and many_many relations using dot notation. The last part of the notation you provide (Title in the example above) will be both the field that’s extracted from the final component, and the $Variable used to access that field inside the loop.

You can even traverse multiple relations at once. For example, $GroupedProducts.GroupedBy('Manufacturer.Employees.FavouriteTeam.Name') would return a list of products grouped by the names of the favourite teams of the employees of the product’s manufacturer.

bigfork-supergroupedlist's People

Contributors

kinglozzer avatar

Watchers

James Cloos avatar helpfulrobot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.