Saturday, October 23, 2010

jqGrid integer sorting

I am working with jqGrid these days and sorting a column with integers was messed up... I was getting the following result:
















It turns out that jqGrid treats a column data as text by default - but you can set it to int or integer to get correct integer sorting

So set sorttype: "integer" in your colModel options

colModel: [{
    name: 'ID',
    index: 'ID',
    sorttype: "int",
    width: 12
},
 
And you will get correct sorting for your numerical columns















More on colModel options here

Sunday, January 3, 2010

Change Application backgroundGradientColors in Flex 3

 <?xml version="1.0" encoding="utf-8"?>  
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">  
 <mx:Script>  
      <![CDATA[  
           private function changeGradientColors():void  
           {  
                Application.application.setStyle('backgroundGradientColors', [colorPicker.selectedColor, colorPicker2.selectedColor]);  
                Application.application.setStyle('backgroundGradientColors', [colorPicker.selectedColor, colorPicker2.selectedColor]);  
           }  
      ]]>  
 </mx:Script>  
      <mx:ColorPicker id="colorPicker" change="changeGradientColors()" x="76" y="52"/>  
      <mx:ColorPicker id="colorPicker2" change="changeGradientColors()" x="76" y="82"/>  
 </mx:Application>  

Tuesday, December 22, 2009

Flex HTTPService Error 1090 when parsing JSON encoded string

Scenario: Flex/AS3's HTTPService component executes PHP code that generates a JSON array (encoded using json_encode) - the code threw the following error:

  
Main Thread (Suspended: [RPC Fault faultString="Error #1090: XML parser failure: element is malformed." faultCode="Client.CouldNotDecode" faultDetail="null"])   
    mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent   
    mx.rpc.http::HTTPService/http://www.adobe.com/2006/flex/mx/internal::processResult   
    mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler   
    mx.rpc::Responder/result   
    mx.rpc::AsyncRequest/acknowledge   
    DirectHTTPMessageResponder/completeHandler   
    flash.events::EventDispatcher/dispatchEventFunction [no source]   
    flash.events::EventDispatcher/dispatchEvent [no source]   
    flash.net::URLLoader/onComplete [no source]   




 This was working perfectly fine till one array element was generated that contained a Unicode character. The string was: "knowing \u2026 how long"

Solution: Make sure method=GET and resultFormat=text
             url="http://localhost/gen_json.php"
                useProxy="false"
                method="GET"

                resultFormat="text"
                result="OnResult()"/>

Thursday, December 17, 2009

Pass data between Facebook PHP app and Flex

I am writing a Facebook Connect application using Flex for front-end with the backend in PHP. This is what my PHP file looks like:

 <?php  
 //filename = "talktofb.php"  
 include_once "facebook.php";  
 $facebook = new Facebook("", "");  
 $ret = $facebook->api_client->fql_query ( "SELECT post_id, message, source_id, attachment from stream where filter_key='nf' and type=46 and source_id in(Select uid from user where uid in (select uid2 from friend where uid1= )) limit 1,5" );  
 echo json_encode($ret);  
 ?>  
This returns the stream of my friends for me (Please note this is for demo only - do not use "type" in your FQL query since this is deprecated )

I use json_encode to return a Javascript/JSON style name-value pair associative array

This PHP code is executed by the Flex application and results retrieved

 <?xml version="1.0" encoding="utf-8"?>  
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"   
   layout="absolute">  
 <mx:Script>  
 <![CDATA[  
  import com.adobe.serialization.json.JSON;  
  public function OnResult():void {  
      var arr:Array = (JSON.decode(userRequest.lastResult.toString()) as Array);  
      for (var i:int=0;i<arr.length;i++){  
                     trace (arr[i].post_id);  
      }   
  }  
      ]]>  
 </mx:Script>  
 <mx:HTTPService id="userRequest"   
         url="http://localhost/talktofb.php"   
                     useProxy="false"   
                     method="POST"   
                     result="OnResult()"/>  
 <mx:Button click="userRequest.send();"   
             label="ClickMe!" width="185" height="42"/>  
 </mx:Application>  
I am using the mx:HTTPService tag to load the PHP script. In order to use the JSON encoded data, I am using as3corelib library. It hasn't been updated for a while but it does the work I need.

In order to make the library available in Flex Builder, you need to unzip the file to a folder, then add it to Menu -> Project -> Properties -> Flex Build Path -> Library Path -> Add SWC... Locate the SWC file in ../as3corelib-.92.1/lib/as3corelib.swc

This is probably not the best way to do it but this is just a quick how-to - took me a full day to figure this out - I hope this helps someone else too

Sunday, December 13, 2009

Flex Builder: How to regenerate html-template file

Product: Flex Builder 3 with Flex SDK 3.0.0

Problem: html-template/.template.html is corrupt and I want to regenerate it

Solution: It's more of a workaround but it worked for me:

1. Go to Project -> Properties -> Flex Compiler , uncheck "Generate HTML wrapper file" and click Apply. Notice the html-template folder is deleted.

Tip:
If the "Properties" menu item is disabled, you need to click inside the editor window so it has focus, before the menu item is enabled

2. Check "Generate HTML wrapper file" and click Apply. Notice the html-template folder recreated - do a "Build All" just in case, or if Automatic Build is turned on, just edit the MXML file and Save.

Friday, November 20, 2009

Zend_tool returns the same (older) version with xampp

I am new to Apache/PHP - Ran into this problem while reading my first tutorial on Zend - "Getting Started with Zend Framework" (html version) - thought I'd share this for anyone else out there searching for this

Zend version: V1.9.5 to D:\Zend\ and decided to try it out - following are the system specs:
OS: WindowsXP
Web server: XAMPP Win32-1.7.2 - PHP ver 5.3.0

Problem:
1. Executing "zf show version" showed me an older version

D:\Zend\bin>zf show version
Zend Framework Version: 1.9.0

2. Zend_Tool starting throwing problems when setting up the Controller:

D:\xampp\htdocs\zf\zf-tutorial>zf create action add index

An Error Has Occurred
A project profile was not found.

Zend Framework Command Line Console Tool v1.9.0
Details for action "Create" and provider "Action"
Action
zf create action name controller-name[=index] view-included[=1] module

Diagnosis:

Opened http://localhost/xampp/ and saw the include_path variable (set in php.ini) shows:

.;D:\installers\xampp-win32-1.7.2\xampp\php\PEAR

Turns out that XAMPP installs Zend as well (at D:\xampp\php\PEAR\Zend) - I had ver 1.9.0

This issue really is a bug in the framework and has been fixed: "zf create controller fails on Windows with ZF 1.9"

Resolution:
Make sure the path contains the folders containing zf.bat and php.exe

PATH
=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;D:\xampp\php;D:\xampp\php\PEAR\Zend

Note: Putting D:\xampp\php in PATH so that php.exe can be found by zf.bat
Putting D:\xampp\php\PEAR\Zend in PATH so that zf.bat can be executed from anywhere

1. Remove the Zend\ folder and replace with the newly downloaded Zend distro (not necessary but good housekeeping)
2. Open php.ini and REPLACE the older include_path path with:
include_path = ".;D:\xampp\php\PEAR\Zend\library"
3. Restart Apache!

Note: Appending to the existing path threw another long error:


***************************** ZF ERROR *******************************
In order to run the zf command, you need to ensure that Zend Framework
is inside your include_path. If you are running this tool without


4. Finally, launch a new console, make sure ENV vars are set correctly, open phpinfo() link in xampp and make sure the include_path is correct and execute:

D:\xampp\htdocs>zf show version

Zend Framework Version: 1.9.5

D:\xampp\htdocs\zf\zf-tutorial>zf create action add index

Creating an action named add inside controller at D:\installers\xampp-win32-1.7.
2\xampp\htdocs\zf\zf-tutorial/application/controllers/IndexController.php
Updating project profile 'D:\xampp\htdocs\zf\zf-tut
orial/.zfproject.xml'
Creating a view script for the add action method at D:\installers\xampp-win32-1.
7.2\xampp\htdocs\zf\zf-tutorial/application/views/scripts/index/add.phtml
Updating project profile 'D:\xampp\htdocs\zf\zf-tut
orial/.zfproject.xml'

and it works!!!! :) - beautiful


Postscript:
I am not sure if replacing the include_path like this breaks anything w.r.t the other PEAR packages...

Thursday, March 13, 2008

first post

I am starting this block to add random tips that i learn (and forget too soon) when writing code - hope it saves someone else some time too - comments/corrections are welcome

Followers