Friday, 15 June 2012

How word-wrap cell text on extjs grid

I use following way to wrap the cell text in extjs grid.

{
 header : 'Error Message',
 dataIndex : 'errorMessage',
 renderer:function(val, meta, record, rowIndex, colIndex, store){
  return '<div style="white-space:normal !important;">'+ val +'</div>';
}
}

Tuesday, 12 June 2012

How to hide grid header in extjs grid

Please use "hideHeaders:true" to hide header in extjs grid.

How to refresh paging toolbar data on store reload

Below code will refresh paging toolbar data on store reload.
(Issue is when you are in second page and try to reload the store, you will see paging tool bar is not refreshing to starting page.)



 store.load({start:0,limit:25});  
 store.loadPage(1);

How deal with checkbox in extjs grid

There are few ways to implement checkbox in extjs grid. However, I feel below one is the good one.

Use below code in grid.
{
  header : 'Reviewed',
  align:'center',
  renderer:function(val, meta, record, rowIndex, colIndex, store){
      return Ext.String.format('<input name="review[]" type="checkbox" value="{       0}">',record.get('id'));
}// here i am passing "id" value as part of check box. 
I  have one button to get those values and use it for further processing.



{
xtype: 'button',
text:'Apply Changes',
listeners : {
 click : function(){
var aunarray = "";
var check = document.getElementsByName('review[]');
var checkLength = check.length;
 for(var i=0; i < checkLength; i++){
  if(check[i].checked){
    aunarray = aunarray+","+check[i].value;
   }
 }
DW.App.getController('AdminNotification').appplyChanges(aunarray);
}
}
}

Wednesday, 30 May 2012

How to construct a queue data structure using stacks


Stacks and queues.

  
Each is defined by two basic operations: insert a new item, and remove an item. When we insert an item, our intent is clear. But when we remove an item, which one do we choose? The rule used for a queue is to always remove the item that has been in the collection the mostamount of time. This policy is known as first-in-first-out or FIFO. The rule used for a stack is to always remove the item that has been in the collection the least amount of time. This policy is known as last-in first-out or LIFO.


construct a queue data structure using only the Single stacks


public class SimulatedQueue<E> { 
    private java.util.Stack<E> stack = new java.util.Stack<E>(); 

    public void insert(E elem) { 
        if (!stack.empty()) { 
            E topElem = stack.pop(); 
            insert(elem); 
            stack.push(topElem); 
        } 
        else 
            stack.push(elem); 
    } 

    public E remove() { 
        return stack.pop(); 
    } 
}


construct a queue data structure using only the two stacks


public class Queue<E> 
{ 

    private Stack<E> inbox = new Stack<E>(); 
    private Stack<E> outbox = new Stack<E>(); 

    public void queue(E item) { 
        inbox.push(item); 
    } 

    public E dequeue() { 
        if (outbox.isEmpty()) { 
            while (!inbox.isEmpty()) { 
               outbox.push(inbox.pop()); 
            } 
        } 
        return outbox.pop(); 
    } 

}

Friday, 18 May 2012

Extjs 4.x Tips and Tricks

I will try to add few points  based on my experience in extjs 4.x.
  • Communication between different controller.(use fireEvent on application)
this.fireEvent('expand', this, cmp, e);
  • Lazy initialization of controller.
someAction: function() {
    var controller = this.getController('AnotherController');
 
    // Remember to call the init method manually
    controller.init();
}
  • Avoid "Id" in coding for reusable component
Don't put id to components, Add id to where it use in your code 
{
  xtype:'customercombo',
  id:'cust-project-field-cust-name'
}
  • Avoid using Ext.getCmp()..use Ext.ComponentQuery  
  • Minimize no of panel in application.
  • Avoid using ownerCt proprety
  • Reduce container nesting
  • Reduce border layout nesting
  • Try to reuse the code
  • Make a cleaner separation between model,view and controller
Only put static code in view and event code in controller and model to store the data
  • Replace Panels with Containers
Panel is more expensive than contaier. Declare   xtype: 'container'  to avoid default panel.
{
 xtype: 'container', // defaultType is 'panel'
 items: [ ... ]
}

Tuesday, 15 May 2012

Ant task to deploy ear file to weblogic server from IDE(Jdeveloper/Eclipse).


Please find steps to deploy ear file weblogic server from IDE.

  • Changes in build.properties file.
    weblogic Deployment properties - Modify as per your weblogic environment
    • weblgoic.deployer.uri=t3://localhost:7001
    • weblogic.admin.user=weblogic
    • weblogic.admin.password=welcome1
    • weblogic.server=SWserver
  • Changes in build.xml file.
  • <property environment="env"/>
    <target name="deploy-weblogic" depends="dist">
    
    <taskdef name="wldeploy"
            classname="weblogic.ant.taskdefs.management.WLDeploy">
      <classpath> 
      <pathelement location="${env.WL_HOME}\server\lib\weblogic.jar"/> 
      </classpath>
    </taskdef>
    <wldeploy action="deploy" verbose="true" debug="true"
    name="${ear.deployment.name}" source="${deploy.dir}/${ear.file}"
    user="${weblogic.admin.user}" password="${weblogic.admin.password}"
    adminurl="${weblgoic.deployer.uri}" targets="${weblogic.server}"  />
    </target>