<?php
$path = MODX_CORE_PATH . 'components/aeiproducts/';
$result = $modx->addPackage('aeiproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$products = $modx->getCollection('Product');
foreach($products as $product) {
$fields = $product->toArray();
$output .= $modx->getChunk('ShowProds');
}
return $output;
?><?php
$path = MODX_CORE_PATH . 'components/aeiproducts/';
$result = $modx->addPackage('aeiproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$c = $modx->newQuery('Product');
$c->sortby('height','ASC');
$products = $modx->getCollection('Product',$c);
foreach($products as $product) {
$fields = $product->toArray();
$output .= $modx->getChunk('ShowProds');
}
return $output;
?><?php
$path = MODX_CORE_PATH . 'components/aeiproducts/';
$result = $modx->addPackage('aeiproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$c = $modx->newQuery('Product');
$c->where(array('cat'=>'CAT'));
$products = $modx->getCollection('Product',$c);
foreach($products as $product) {
$fields = $product->toArray();
$output .= $modx->getChunk('ShowProds');
}
return $output;
?>This question has been answered by BobRay. See the first response.
You can use one snippet, with variables for the sorting criteria and filtering. Get these variables from the POST of a form. The form will be on the page, with radio buttons, check boxes, or drop-down selects as seems appropriate. You can ether refresh the page, or use AJAX to post the form.Hi Susan,
Style the checkboxes and radio buttons so they don't look like standard form fields if you like. Have each option be a pretty button, and use AJAX to change the view when the button gets clicked. Be creative!
http://jqueryui.com/button/#default

<?php
$path = MODX_CORE_PATH . 'components/aeiproducts/';
$result = $modx->addPackage('aeiproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$cw = $modx->newQuery('Product');
$cw->sortby('width','ASC');
$ch = $modx->newQuery('Product');
$ch->sortby('height','ASC');
$cc = $modx->newQuery('Product');
$cc->where(array('cat'=>'CAT'));
$products = $modx->getCollection('Product');
foreach($products as $product) {
$fields = $product->toArray();
$output .= $modx->getChunk('ShowProds');
}
return $output;
?><?php
$sortby = isset($_POST['sortby')) ? $_POST['sortby') : 'height';
$sortdir = isset($_POST['sortdir'])) ? $_POST['sortdir'] : 'ASC';
$filter = isset($_POST['filter'])) ? $_POST['filter']] : 'CAT';
// repeat for all the POST values the form can send
$query = $modx->newQuery('Product');
$query->sortby($sortby,$sortdir);
$query->where(array('cat'=>$filter));
If possible, I would do it with a single snippet that used the information from the user to customize the query.Hi Bob,
You could do it with JS and an Ajax call (in which case the "snippet" would actually be a processor) or by having the user submit a form with options selected in the form.
ExtJS/modExt does the grids in the Manager and some extras with modExt. They can often be sorted on any field (either way) by clicking on the column heading or a drop-down arrow. You can also add a search filter to limit the output.
The Batcher extra is a good example. The CMP that comes with MyComponent is another.
In theory, you can use CSS to make the "grid" look however you want it to.
You might also be able to do this with MIGX.
The form works like any form, its action will be the same page, and the snippet grabs the POST to get the variables to use for sorting and filtering. Set a sane default for the case where the POST is not set.Okay, I made some headway but it's not working yet!
<!--?php $sortby = isset($_POST['sortby')) ? $_POST['sortby') : 'height'; $sortdir = isset($_POST['sortdir'])) ? $_POST['sortdir'] : 'ASC'; $filter = isset($_POST['filter'])) ? $_POST['filter']] : 'CAT'; // repeat for all the POST values the form can send $query = $modx--->newQuery('Product'); $query->sortby($sortby,$sortdir); $query->where(array('cat'=>$filter));
I'm pretty sure xPDO automatically sanitizes your input, see https://forums.modx.com/thread/82128/security-problem-if-not-sanitizing-data-before-saving-by-xpdo-to-a-database
<?php
$path = MODX_CORE_PATH . 'components/aeiproducts/';
$result = $modx->addPackage('aeiproducts',$path .
'model/','aei_');
if (! $result) {
return 'failed to add package';
}
$sortN = isset($_POST['sortbyname']) ? $_POST['sortbyname'] : 'itemno';
$sortH = isset($_POST['sortbyheight']) ? $_POST['sortbyheight'] : 'height';
$sortW = isset($_POST['sortbywidth']) ? $_POST['sortbywidth'] : 'width';
$filter = isset($_POST['filter']) ? $_POST['filter'] : 'CAT';
$c = $modx->newQuery('Product');
$c->sortby($sortN,'ASC');
$c->sortby($sortH,'ASC');
$c->sortby($sortW,'ASC');
$c->where(array('cat'=>$filter));
$products = $modx->getCollection('Product', $c);
foreach($products as $product) {
$fields = $product->toArray();
$output .= $modx->getChunk('ShowProds', $fields);
}
return $output;<form action="[[~[[*id]]]]" method="POST"> <select name="sort" onchange="this.form.submit()"> <option value="sortbyname">Sort by Name</option> <option value="sortbyheight">Sort by Height</option> <option value="sortbywidth">Sort by Width</option> <option value="filter">Only Show This Category</option> </select> <noscript><input type="submit" value="Submit"></noscript> </form>
It appears that you only want to sort by one attribute. In that case you only want one sort variable and one sortby statement as in Susan's example.Hi Bob,
I'm not sure I understand what you're trying to do. You have 'filter' in the array of sort options but it isn't really a sort option. Maybe it should be a separate input, outside the sort options, which would allow users to select the filter *and* a sort option. Also, shouldn't there be a way for the user to select a category to show, or is there only one category available there?