guys!
I`d like to make 'clever pagination'. For example, if i already have params.category=Auto - i want it to be added to my params.
Of course, i can do smth like this :
<g:paginate total="${total}" max="10" maxsteps="5" params="[category: params.category,subcategory: params.subcategory]"/>
But if current params.subcategory is null - it will also be added to url ( ?subcategory=&category=Auto) . I don`t want to have 'subcategory=' in my params in such a case!
Also I can do it with string concatenations to create new url - but maybe grails have some cheats/mechanism to create new url without string concatenations?
Cheers, Dmitry.
There aren't any great solutions I can think of. You could try:
params="${[category: params.category,subcategory: params.subcategory].findAll {it.value} }"
Alternatively, provide your own custom tag that strips out null param values before delegating to the paginate tag.
Related
I am returning data from my DB with multiple phrases. One of them being the following text : Submitted an Idea
I want to make the "Idea" in any an all text a hyperlink, so I want to use a replace function in my razor view to replace the word "Idea" with my Html Helper:
#item.RewardType.Replace("Idea", #Html.ActionLink("Idea", "ChallengeIdea", "Ideas", new { id = item.fkiIdeaId }, null))
I've looked around a bit but can not really find anything. Someone suggested using #Url.Action - But the issue remains the same.
How do I do this ? Or is using an Html helper the wrong way of doing this ?
Thanks for any help.
You can try this:
#Html.Raw(item.RewardType.Replace("Idea", $"<a href='/ideas/challengeidea/{item.fkiIdeaId}'>Idea</a>"))
Or
#Html.Raw(item.RewardType.Replace("Idea", "Idea"))
Html helpers are there to help you in general situations. When they produce more complications than value, they have no use
<span>Submitted an Idea</span>
If you have RewardType in a resource and can not use plain html, you could set RewardType to "Submitted an Idea" And use string.format
I'd like to set the 'active' class on an Ember link-to helper for more than one route, where the routes are not nested.
ie. if I have a link to route1 I would like it to be active when the current route is route1 or route2.
Something, like:
{{#link-to 'route1' currentWhen="route1, route2"}}Things-N-Stuff{{/link-to}}
My next ideal scenario is set (or find) a boolean when the route is active and then do something like:
{{#link-to 'route1' class="isRoute1:active isRoute2:active"}}Not-as-good{{/link-to}}
But I'd rather pick it up for free. Perhaps there is a default isRoutename boolean that isn't in the docs yet...?
No answers yet. I ended up doing this:
{{#linkTo "things" tagName="li" href=false}}
<a {{bindAttr href="view.href"}} {{bindAttr class="isThingsLinkActive:active"}}>Things</a>
{{/linkTo}}
And then in the App.ApplicaitonController
isThingsLinkActive: function(){
return ['things.index','thing.index','stuff.index'].contains( this.get('currentPath') );
}.property('currentPath'),
It means I need to have something like thins in my app controller for each 'overloaded' link. Wouldn't it be cleaner to capture this entirely in the template using default flags/attributes generated by ember? I'm open to a more elegant solution... anyone?
According to the link-to#active documentation, you can do this by using a space delimited "currentWhen", but this requires Ember 1.8.
{{#link-to 'route1' currentWhen="route1 route2"}}Things-N-Stuff{{/link-to}}
This may also be a feature you can enable on earlier builds:
See 'ember-routing-multi-current-when' on https://github.com/emberjs/ember.js/blob/master/FEATURES.md
Alternatively, you can override the link-to helper with one of the methods described in this SO post:
Is there a way to pass an array to currentWhen in EmberJS?
Currently as of 3.2 the correct syntax is:
{{#link-to 'fruits.index' current-when="fruits.index apples.index"}}Link text{{/link-to}}
Sorry, tried to edit the original answer but the change is less than 6 characters.
I have a normal tag:
...
I need it to look like this:
<a href="prefetchThisPage.html" data-prefetch> ... </a>
Why? jQuery Mobile feature: http://jquerymobile.com/demos/1.1.1/docs/pages/page-cache.html
The expected way below does not add the attribute, probably because Tritium ignores empty attributes.
attribute("data-prefetch")
Any ideas?
Great Question!
The best way to do this, is to set the value of the variable to the NAME of the variable.
I would do it like this:
$variable_name = "data-prefetch"
$("./a") {
attribute($variable_name, $variable_name)
}
This is an HTML5 convention and should work for the purposes you illustrated!
Tritium currently has a short circuit that converts attribute assignments like the following declaration:
attribute("data-prefetch", "")
Into the equivalent of removing the attribute.
I strongly recommend you file this issue with Moovweb's help desk so that they add support for adding attributes with no values.
Using Yii 1.1.12. I have a CListView with ajax turned off:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'ajaxUpdate' => false,
)); ?>
The url for the link to the second page looks like:
http://www.example.com/products?Product_page=2
I want the url to look like:
http://www.example.com/products?page=2
How can I achieve this?
(A bonus would be to also describe how to get a url like http://www.example.com/products/page/2)
Update
As pointed out by elbek, I see the CListView has a pager property of type CLinkPager. This in turn has a pages property of type CPagination which has a property pageVar which is described as:
name of the GET variable storing the current page index. Defaults to
'page'.
Sounds like it could be what I'm looking for, not sure how to modify this from the CListView though.
Additionally to change the pageVar you have to modify the $dataProvider. You can do this when you are defining it in the controller action:
$dataProvider=new CActiveDataProvider('Products',array(
'pagination'=>array(
'pageVar'=>'page'
)
));
Alternatively you can of course modify the $dataProvider in the view itself before using it in the CListView : (not recommended-owing to separation of concerns)
$dataProvider->pagination=array('pageVar'=>'page');
$this->widget('zii.widgets.CListView', array(/*rest of your code*/));
But with this change, to make your url look like http://www.example.com/products/page/2 you'll need to slightly change the rule in urlManager from Suvera's answer:
'products/page/<page:\d+>'=>'products/index',
Note: If you don't need that type of url, you don't need the above rule, just specifying the pageVar does it.
enable the urlManager component on your config. And add the following rule at the top.
'urlManager'=>array(
......
'rules'=>array(
'products/page/<Product_page:\d+>'=>'products/index', //Add it in top
...........
...........
),
),
the above rule will create a url something like http://www.example.com/products/page/2
The value part in the rule products/index is products controller and index action (this is important, so point it out to your actual route).
you can even create urls whatever way you want.
ex 1:
'products/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/products/2
ex 2
'TheAvengers/vs/Loki/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/TheAvengers/vs/Loki/2
I think CListView has pager attribute(from its parent class)
You can try to set some attributes for this. I think it is CLinkPager instance.
I have actions that take string id parameters that are based on a username which can include characters that require encoding, for instance "user?1"
If I use ActionLink() to generate the links, passing the string without encoding, it generates a link like this: http:\\localhost\controller\action\user?1, and the action gets passed "user" as the id.
If I UrlEncode() the string before passing it to ActionLink, then the link generated is: http:\\localhost\controller\action\user%253f1 as ActionLink will then encode the '%' character for you. Besides this looking ugly, it then also generates a HTTP Error 400 - Bad Request when following the link which I've not yet tracked down the cause of.
Is there any way that I can generate the url like: http:\\localhost\controller\action\user%3f1?
How about removing the ? character or replacing it with something else like a dash (-) or underscore (_) ?
You should look in the Global.asax.cs file
add another route for your convenience, in this case, the ff. might work:
routes.MapRoute(
null,
"{controller}/{action}/user/{id}",
new { controller = "Home", action = "Index" }
);
I guess this is what you want, to separate action for each users, but i suggest you use cookie for this purpose.
PS: Remember to put that one on top of your default route since routing is trying to match from top to bottom.
you can create a jquery plugin that check all the links and replace the char that you need to replace with the new value.
and after apply this plugin to all the ActionLinks