How to relate to the rows' entities in custom sort functions in ng-grid? - angular-ui

I followed the documentation in https://github.com/angular-ui/ng-grid/wiki/Sorting-and-filtering
but the only informaiton passed to the custom sort function are the values of the cells in the relevant column.
I'd like to access other columns within the custom sort function.
e.g.:http://plnkr.co/edit/FvcKQjkUv1eeoYPzjdRD?p=preview
I'd like to sort by name after taking the role into consideration. This would be easy if the row entity was supplied or something of sorts.
Thank you for any assistance.
Yuval

try to implement by header template and the whole control is in your hand fro sorting the callback goes to a function where you can do anything you want
var myHeaderCellTemplate = '<div class="ngHeaderSortColumn {{col.headerClass}}" ng-style="{cursor: col.cursor}" ng-class="{ ngSorted: !noSortVisible }">'+
'<div ng-click="sortByMyPreference()" ng-class="\'colt\' + col.index" class="ngHeaderText">{{col.displayName}}</div>'+
'<div class="ngSortButtonDown" ng-show="ID.down"></div>'+
'<div class="ngSortButtonUp" ng-show="ID.up"></div>'+
'<div class="ngSortPriority">{{col.sortPriority}}</div>'+
'<div ng-show="col.resizable" '+
'class="ngHeaderGrip" '+
'ng-click="col.gripClick($event)" '+
'ng-mousedown="col.gripOnMouseDown($event)"></div>';
here is the plunker http://plnkr.co/edit/OxyV1NlgznEJ8ulNAkt2?p=preview
i have left the implementation of sorting upto you click the Name Tab it will show you an alert and ID.down and ID.up you can toggle by true false to show arrows

Related

Wordpress + ACF, display random post images from each post on home page

I’m new to Advanced Custom Fields and a novice in WP, I'm interested in creating a random slider in my homepage where each post has many images.
I’m not 100% sure how to combine the wp_query with the ACF repeater, where multiple posts are involved, I did succeed in doing this in a single post page.
I am less interested in specs on how to do this, nor PHP functions, i’m well versed in both, the issue is the WP functions and conventions
If someone already done something like this and can advise how to begin this with combining the ACF repeater functions together with the wp_query, from there i'd know how to shuffle the images of each post with array_rand.
if a Gist/fiddle exists, would be even better.
You could use the shuffle PHP function to randomise the array the repeater field outputs then slice out the amount of slides that you want. Something like this:
$rows = get_field('repeater_field_name'); // Get row array
shuffle($rows); // Shuffle the array in a random order
$rows = array_slice($rows, 0, 5); // Slice out the first 5 elements of the array
if($rows)
{
echo '<ul>';
foreach($rows as $row)
{
echo '<li>sub_field_1 = ' . $row['sub_field_1'] . ', sub_field_2 = ' . $row['sub_field_2'] .', etc</li>';
}
echo '</ul>';
}
If you're just using the repeaters for images, I would suggest using the "Gallery" element rather than the repeater, and doing the same thing.

Multiple values set on select2 in WordPress

I have been trying to show multiple selected values in select2 dropdown. So, far I have developed the dropdown and saved the selected values.
I have the following code as the options for the dropdown:
<option value="<?php echo esc_attr($post->ID);?>"><?php the_title();?></option>
Note: The options are on loop.
Now, I can not set those multiple values to select2 on page load. Those multiple values only set if any option is selected from the dropdown again.
My code is mentioned below:
if ( isset( $wp_travel_engine_setting['crosssell']['trips'] ) && $wp_travel_engine_setting['crosssell']['trips']!='' )
{
$selectedval = $wp_travel_engine_setting['crosssell']['trips'];
}
echo
'<script>
jQuery(document).ready(function($){
$("#wte-cross-sell-'.$post->ID.'").select2();
var arrayFromPHP = '.json_encode($selectedval).';
console.log(arrayFromPHP);
$("#wte-cross-sell-'.$post->ID.'").val(arrayFromPHP);
$("#checkbox").click(function(){
if($("#checkbox").is(":checked") ){
$("#wte-cross-sell-'.$post->ID.' > option").prop("selected","selected");
$("#wte-cross-sell-'.$post->ID.'").trigger("change");
}else{
$("#wte-cross-sell-'.$post->ID.' > option").removeAttr("selected");
$("#wte-cross-sell-'.$post->ID.'").trigger("change");
}
});
});</script>';
//variable $selectedval will get us the array of selected value ids like this as seen on browser console:
(2) ["1301", "1024"]
Can anyone please shade some light on this? How can I set the values on pageload without choosing the option again.
Thanks for your time!
Kind regards,
It was my silly sort of mistake. I forgot to trigger the select2 change call.
So, the line $("#wte-cross-sell-'.$post->ID.'").val(arrayFromPHP) will now be
$("#wte-cross-sell-'.$post->ID.'").val(arrayFromPHP).trigger("change");
Hope it will help anyone in the future!

WordPress Advanced Custom Fields: Only pull attachments from custom field, not entire post

I'm using 2 custom fields... left_column & right_column which are WYSIWYG..so can add imagery... I want to runa check that "IF theres imagery, then add the class 'image_box'...
The thing is, I can get to identify images...but applying the logic to both columns...pulls in 2 sets of the images...regardless of what column (left or right) they were added to.
My code:
if(get_sub_field('extra_left_column')){
if(get_sub_field('extra_left_column', $attachemnt['ID'])) {
$extra_column_right.= '<div class="col6 right_column image_box">'.wpautop(apply_filters('the_content',get_sub_field('extra_right_column'))).'</div>';
} else {
$extra_column_right.= '<div class="col6 right_column">'.wpautop(apply_filters('the_content',get_sub_field('extra_right_column'))).'</div>';
}
}
if(get_sub_field('extra_right_column')){
if(get_sub_field('extra_right_column', $attachemnt['ID'])) {
$extra_column_right.= '<div class="col6 margin_left right_column image_box">'.wpautop(apply_filters('the_content',get_sub_field('extra_right_column'))).'</div>';
} else {
$extra_column_right.= '<div class="col6 margin_left right_column">'.wpautop(apply_filters('the_content',get_sub_field('extra_right_column'))).'</div>';
}
}
I thought my code would be 'column specific' but it's not....if I add images only to my 'Righ tColumn' fileds within a post...it also pulls the same imagery into the 'left column' on the live site... so I've got duplicates... not good.
First of all dump the values of both the subfields to see what data is being returned. If its just an empty field then, you can check for !empty() or !== ''.
If you are using v3.3.4 or later you can alos use a function called has_sub_field, to check if the field was set.

Wordpress menu items order

basically I have a three-level menu in wordpress and I've got the following code in the front-end to call the third-level menu:
$children = get_pages('child_of='.$include_page_ids[$i]);
if (count($children) > 1) {
$sub = "<ul>";
foreach ($children as $child){
$sub .= "<li><a href='#$child->post_title'>";
$sub .= $child->post_title;
$sub .= "</a></li>";
}
$sub .="</ul>";
echo $sub;
}
This calls a list for the children of a certain page and also makes the the anchors (which I also need). The problem is that right now they are being displayed in an alphabetical order, but I need to be able to set the right order myself (ie to be the same as in the backend menu). Please hepl me with it, how can I achieve this? For example this is the page http://www.eboxlab.net/transbeam/support/support/, youcan see the third level-menu as the box right next to the banner (Acceptable Use Policy to Terms & Conditions). THe order of the blocks which it corresponds to is right, but the menu is alphabetically ordered.
Help really appreciated.
PS: if you need I can provide the template code
It's pretty simple actually. Here is what your $children call should look like:
$children = get_pages('child_of=' . $include_page_ids[$i] . '&orderby=menu_order&sort_order =ASC');
That's all you need to add - this tells the query to order pages in ascending fashion by their "menu_order" column(or the "Order" field under Page attributes). You can see more details on the get_pages function at Function Reference/get pages
wp_nav_menu to the rescue! Assuming you're using WP 3 or newer, it will let you wrap elements in whatever markup you'd like, and will correspond to however you've configured the menu in the admin Dashboard.

Adding sorting to a view on Drupal?

I used to know how to do this, but I can't seem to get sorting to work on a view where filters are exposed in a block. I want to be able to filter by, for example, type, price etc, but then also have sorting options to sort by these items.
How do I get sorting to work like this?
I used that code to override sorting in non-table views
function views_tweak_views_query_alter(&$view, &$query) {
if ($view->name == 'products'){
if (arg(3) == 'pu') $query->orderby[0]='uc_products_sell_price ASC';
if (arg(3) == 'pd') $query->orderby[0]='uc_products_sell_price DESC';
if (arg(3) == 'nu') $query->orderby[0]='node_title ASC';
if (arg(3) == 'nd') $query->orderby[0]='node_title DESC';
}
}
and placing into view template links with those urls
AFAIK you can't expose sort criteria like you can with filters.
I looked a bit around a found this module. The idea is to create several views each with a different sort criteria and link them together with tabs. It's a bit hackish and might not work with exposed filters. The module is still in beta release, and I haven't tested it, so can't say if it's any good.
If you choose to use a table layout, you can sort by columns. That functionality is built into views.
Just in case you cannot find where to set this, look on the left side of the View (in Edit mode), under Basic Settings, select "Table". The click the "settings" (looks like a little gear icon to the right of the "table" selection), and you'll see a list of all the display fields, where you can select which ones are sortable/not, and which is the default sort.
Adding sorting to a view on Drupal less programm code in hooks.
You need to use arguments in display page.
Use taxonomy menu for pages before.. Next:
Create one display page in view with path (for example):
some_path/%/by_totalcount
1.1. Make sort criteria for this display by totalcount
Make another one dislplay page in this view with path (for example):
some_path/%/by_date
2.1. Make sort criteria for this display by date
Create new block with code:
<?php
$url= urldecode($_SERVER['REQUEST_URI']);
switch($url)
{
case '1':
$class = 'top';
$title_h2 = 'top';
break;
case '/taxonomy/term/6 3 ':
$class = 'travel';
$title_h2 = 'travel';
break;
.................
}
global $base_url;
$url_rating = $base_url.'/'.arg(0).'/'.arg(1).'/'.arg(2).'/rating';
$url_created = $base_url.'/'.arg(0).'/'.arg(1).'/'.arg(2);
?>
<div class="<?php print $class; ?>">
<div class="title">
<h2>
<?php print $title_h2; ?></h2>
<p>Sort node: <span class="sort_type">by rate</span> | <span class="sort_type"> by date</span></p>
</div>
</div>
<p> </p>
VOILA
Sorry for my english.. it isn't my native language ))

Resources