How do I search with the "&" keyword, e.g I want food & drink - bootstrap-table

In bootstrap-table jquery (http://issues.wenzhixin.net.cn/bootstrap-table/)
How do I search with the "&" keyword, e.g I want food & drink.
However, when read the source code, it has .replace for /&/ to &. Any idea I can bypass this? It is impossible to ask user to key in & in the search text box.

So... im still a little unclear as there is no bug in core code.
See this fiddle which proves "&" search works fine:
http://jsfiddle.net/dabros/x8efv6wf/1/
If this somehow doesnt answer your needs, elaborate on exactly why.
Then look at some extensions like multiple search, filter and filter-control:
http://bootstrap-table.wenzhixin.net.cn/extensions/
If still not happy, then create a custom search function. Easy to do if using server-side pagination, but possible even if client-side.
If you fixed on using client-side (not server side pagination + search, meaning that the js does the search, not your own server code) then look at custom search.
Relatively new feature i think, not used it myself as if i wanted a custom search i would use server-side code.
But here it is:
Custom search function #1956
https://github.com/wenzhixin/bootstrap-table/issues/1956
How to search within row details? #2007
https://github.com/wenzhixin/bootstrap-table/issues/2007
https://github.com/wenzhixin/bootstrap-table/pull/1979
That pull requests seems most detailed, it appears full example still otw, but shouldnt be hard if you read through there.
Though frankly, stick with plugins/extensions i listed above or use server-side code if still not happy - gives you far greater control with far simpler execution/code-maintenance.

Related

How to define google_tag_params in Google Tag Manager?

i want to create a dynamic remarketing campaign in Google Ads, but i have to let GTM know where to extract the information for ecomm_prodid, ecomm_pagetype, ecomm_totalvalue and ecomm_category from my website. I understand that i have to create a Data Layer Variable but i just don't know how to make those tags extract the necessary info from my website. I also know that you should be able to see in Google Tag Assistant the Metadata for your products (price, brand, category etc) in the Dynamic Remarketing Tag. Unfortunately i cannot add code to my website as it was created on a platform that doesn't allow custom code, so i have to use GTM.
For example the class for the price is: fPrice -g-product-final-price-258. Shouldn't ecomm_totalvalue take info from this class? I tried reading Help pages from google but they are soooo confusing, i cannot understand them.
If anyone would help me with this i would be very grateful.
Thanks
I know this is 10 months late but this might help you or lead someone arriving here to hopefully the right direction and/or solution. I came across your question unanswered when looking for something else. It seems you have two questions so I'll try to answer both.
For starters you might want to have a quick look at the GTM Dynamic Remarketing Documentation.
Question 1: Where to extract the information for [variables] ?
You are on the right track with the dataLayer here. Usually you need to implement that with custom Javascript on your website (which in your case you can't do / see below for that). You would usually populate a events & variables with dataLayer.push() function.
Here is a sample of how that could look:
dataLayer.push({
'event': 'your_event_name',
'a_container_name' : {
'key1' : key_var_1,
'key2' : key_var_2, }
})
You can also do inner structures within those structures (nested dictionary).
Once those are populated you can create variables in Google Tag Manager (GTM) and simply pick up the values with the naming convention you've used separated by a "." (dot). For the above you could for example do: "a_container_name.key1" which would then populate the variable in GTM with the value of "key_var_1".
You can use the event name (here: 'your_event_name') as the trigger for the Tag in GTM to fire your Tag.
So in your case you would usually want the variable "ecomm_prodid" taken from the webpage with a bit of javascript and pushed into the dataLayer for you to pick up in GTM as described.
Question 2: I cannot add code to my website, what can I do ?
While this is entirely possible it is unfortunately a bit more tedious and potentially much more error prone. In this case you have to read the values you want directly from your website through GTM.
You can use custom javascript inside variables in GTM. To do so click on "variables", then click on "New" and select "Custom Javascript". You can then use pretty much any javascript here to basically scrape the value off your website based on id, class or any other HTML identifiers. There are tons of options on how to do that. You have to use what works best for you.
However this is potentially very error prone. Here is why:
You've stated that your class for the price is "fPrice -g-product-final-price-258". This looks to me very much like an auto generated identifier. Next time you look at that product or pick another one it is most likely different. So your option is to take either another unique identifier or use a sub-string of that one (e.g.: fPrice -g-product-final-price only). But keep in mind if your website ever updates or changes those class names the javascript you wrote instantly will not work any longer.
So it is important to pick some robust form of identifier or write the javascript code so that it will last. As mentioned, the jvascript to scrape or read directly off your website can be as custom as you like. Here is a crude example of how this would look like.
var text = ''; // empty value placeholder
if (document.getElementsByClassName("YOUR_SPECIFIC_CLASS_NAME")) {
....loop through returned elements if applicable....
....do stuff here or check stuff here...
text = SOME_ELEMENT.innerHTML;
console.log(text) // helps to debug your code
}
return text
Again this is only a crude example but if you get this to work then you can simply use the populated variable in your Tag in any field that supports variable with the double curly brackets: {{YOU_TAG_MANAGER_VARIABLE_NAME}}
I hope this helps and gives you a bit on an insight. Good luck!
PS: By the way. If you can't edit your code because of your website provider or website engine then I would strongly recommend moving away from it. As you can see it would save you a ton of headache. For smaller to mid sites and smaller e-commerce stores use Wordpress. For larger stuff there are other solutions. In any case there are some website builders out there that are simply really bad but at the same time very misleading. Basically leading you to the problems as you've described. Don't use them :)

Aggregating from various sources

It could be a project well beyond my skills right now but I've got around one full month to spend on it so I think I can do it. What I want to build is this: Gather news about a specific subject from various sources. Easy, right? Just get the rss feeds and display them on a page. Well, I want something more advanced: Duplicates removed and customized presentation (that is, be able to define/change the format in which the news headlines are displayed).
I've played a bit with Yahoo Pipes and some other tools and I am facing two big problems:
Some sources don't provide rss feeds. How do I create one?
What's the best method to find and remove duplicates. I thought about comparing the headlines and checking if there is a matching bigger than, say, 50%. Is that a good practice though?
Please add any other things (problems, suggestions, whatever) I might not have considered.
Duplication is a nasty issue. What I eventually ended up doing:
1. Strip out all HTML tags except for links (Although I started using regex, I was burned. I eventually moved to custom parsing to remove tags)
2. Strip out all whitespace
3. Case-desensitize
4. Hash all that with MD5.
Here's why you leave the link in:
A comment might be as simple as "Yes, this sucks". "Yes, this sucks" could be a common comment. BUT if the text "this sucks" is linked to different things, then it is not a duplicate comment.
Additionally, you will find that HTML tag escaping is weird with RSS feeds. You would think that a stray < would be double-encoded: (I think)&<;
But it is not. It is encoded <
But so too are HTML tags! :<p>
I eventually copied all the known HTML tags as parsed by Mozilla Firefox and manually recognized those tags.
Creating an RSS feed from HTML is quite nasty and I can only point you to services such as Spinn3r, which are fantastic at de-duplication and content extraction. These services typically use probability-based algorithms that are above me. I know of one provider that got away with regexing pages (They had to know that a certain page was MySpace-based or Blogger-based) but they did not perform admirably.
You might want to try to use the YQL module to scrape a webpage that doesn't provide RSS. Here's a sample of a YQL statement to scrape HTML.
About duplicates, take a look at this pipe.
Customized presentation: if you want it truly customized you'll have to manipulate the pipe results yourself, e.g. get it as JSON an manipulate it with Javascript, or process it server-side.

Token replacement

I currently implement a replace function in the page render method which replaces commonly used strings - such as replace [cfe] with the root to the customer front end. This is because the value may be different based on the version of the site - for example the root to the image folder ([imagepath]) is /Images on development and live, but /Test/Images on test.
I have a catalogue of products for which I would like to change [productName] to a link to the catalogue page for that product. I would like to go through the entire page and replace all instances of [someValue] with the relevant link. Currently I do this by looping through all the products in the product database and replacing [productName] with the link to the catalog page for that product. However this is limited to products which exist in the database. "Links" to products which have been removed currently wont be replaced, so [someValue] will be displayed to the user. This does not look good.
So you should be able to see my problem from this. Does anyone know of a way to achieve what I would like to easily? I could use regexes, but I don't have much experience of those. If this is the easiest way, using "For Each Match As String In Regex.Matches(blah, blah)" then I am willing to look further into this.
However at some point I would like to take this further - for example setting page layouts such as 3 columns with an image top right using [layout type="3colImageTopRight" imageURL="imageURL"]Content here[/layout]. I think I could kind of do this now, but I cant figure out how to deal with this if the imageURL were, say, [Image:Product01.gif] (using regex.match("[[a-zA-Z]{0,}]") I think would match just [layout type="3colImageTopRight" imageURL="[Image:Product01.gif] (it would not get to the end of the layout tag). Obviously the above wouldn't quite work, as I haven't included double quotes in the match string or anything, but you get the general idea. You should be able to get the general idea of what I am getting at and what I am trying to do though.
Does anyone have any ideas or pointers which could help me with this? Also if this is not strictly token replacement then please point me to what it is, so I can further develop this.
Aristos - hope reexplaining this resolves the confusion.
Thanks in advance,
Regards,
Richard Clarke
#RichardClarke - I would go with Regular Expressions, they're not as terrible to learn as you might think and with a bit of careful usage will solve your problems.
I've always found this a very useful tool.
http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx
goes nicely with a cheat sheet ;-)
http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/
Good luck.

Style Google dictionary API results

I have no idea what I am doing, but I keep trying. I have been trying to find a way to add a dictionary search box to my school website for my 3rd grade (7-8 year olds). Most of the dictionary sites are too complex and riddled with inappropriate advertisements. I found out about google/dictionary.com the other day and have been trying to figure out how to create a custom search with it.
I asked for help here before and was able to get a script that passed a word to the dictionary and displayed the results in an Iframe. Which works ok but it is a full page and I can't change the size of the page in the Iframe.
I came across this
http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=school&sl=en&tl=en&restrict=pr%2Cde&client=te
Where "school" is the word that is looked up.
However I can't figure out how to style the results, any ideas?
I suggest you dont use this url(API) as it is against google policy. It violates the contract google has with its providers, google asked a developer who made a dictionary extension for chrome to stop using the api.
The result is coming back in JSON. You'll probably want something that can parse JSON, and then you can output the result in whatever form you like, based on the data from the result.
You need to be a little conversant with javascript since the results are sent back as a javascript object ie the result is sent back as json text which you need to parse to retrieve the contents. To parse the contents you can use the javascript eval() function.

Should I use Replace() instead of HtmlEncode()?

Should HtmlEncode() be abandoned and Replace() used instead of I want to parse links in posts/comments (with regular expressions)? HtmlEncode() replaces & with & which I assume can cause problems with links, should I just use Replace() to replace < with <?
For example if a user posts something like:
See this site http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3
I want it to be:
See this site <a href="http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3">http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3</a>
But With HtmlEncode() the URL will become (notice the ampersand):
See this site http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3
Should I avoid the problem by using Replace() instead?
Thanks
Actually, your last example - the one you're worried about - is the only correct one. In HTML documents, ampersands are used to introduce entity references, and therefore must be escaped. While most browsers are forgiving enough to let them slip through when not obviously part of an entity reference, you can run into subtle problems should their use in a URL happen to look like an entity.
Let HtmlEncode() do its job.
Perhaps you are looking for UrlEncode()?
http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
What are you looking to replace and why? HtmlEncode() is typically used to sanitize user-supplied data. That said, if you're allowing users to submit links, you probably don't want to HtmlEncode them, in the first place. You're basically going to render them exactly as the user supplied them.
Replacing & with & inside of an href attribute is correct. If you do not, then your code is technically invalid. Also, you should escape it even if it's inside of a link. The only case you'll run into problems is if you end up HTMLEncoding it multiple times.
I recommend against using Replace to do the job of HTMLEncode or URLEncode. These functions are custom designed to take care of most of the problems that you'd see in user entered content and if you try to replace them with your own code, the results might get ugly (I am talking from experience here) if you forgot something vital.

Resources