Archive for November, 2014

Encode String to Only Alphanumeric Chars

November 27th, 2014 No comments

If you need to encode a string with all sorts of problem characters into a URL-safe string, urlencode() is not right solution.

What you need is a function that will give you only numbers and letters. No %’s or &’s, spaces, or any other non-alphanumeric character.

For this we will use PHP’s bin2hex() function, and its pack() function.

For example, it can convert: “(!X>4Ob=h/&hN\'” into this much nicer string: “2821583e344f623d682f26684e5c27”.

Here are the functions you need:

function hex_encode($string)
    return bin2hex($string);

function hex_decode($string)
    return pack("H*", $string);
Categories: PHP Tags:

Adding QTips to GridPanel cell in ExtJS 4.0

November 8th, 2014 No comments

Need to add a custom tooltip (quick tip) to cell in a GridPanel in ExtJS 4.0? In your column definitions, simply add a attribut “rendered”, passing a custom function.

columns [
        metaData.tdAttr = 'data-qtip="' + value + '"';
        return value;

A couple notes:

  1. To show tooltip, you need to add line “Ext.QuickTips.init();” before Grid definition
  2. data-qtip is one of four attributes for tooltip. Tooltip attributes are:
    • data-qtip – Set tooltip text content
    • data-qtitle – Set the title
    • data-qwidth – Set tooltip width
    • data-qalign – Represented by a reference point that corresponds to the original, which reference point. For example: “tl-br” is represented by the tip of the upper left corner, corresponding to the lower right corner of the original

With such a modification, you get a nice tooltip generated for each cell in your grid.

Categories: JavaScript Tags: , ,