GridPanel templatecolumn

  1. #1

    GridPanel templatecolumn databind

    hi
    I know that we can use template column to create customize column with one or more datafields

    for example,the code as below create a TemplateColumn with 2 datafields : {amount} and {numberCol}
       <ext:TemplateColumn  MenuDisabled="true" Header="Template">
                            <Template runat="server">
                                <Html>
    						        <tpl for=".">
    							        {amount}<br />
    								    {numberCol}<br />
    						        </tpl>
    					        </Html>
                            </Template>
                        </ext:TemplateColumn>
    But how can i performing a logic operation on these two datafields ?

    e.g
    I'd like this templatecolumn to show the result of {amount}/{numberCol}
    or
    ({amount}>0)?{numberCol}:0
    Last edited by dew3083142; Nov 01, 2012 at 12:40 AM.
  2. #2
    You cannot use ?: operator. To check logical expressions you can use only 'if' operator, but usually this is enough.

    Example:

    <ext:TemplateColumn  MenuDisabled="true" Header="Template">
    	 <Template runat="server">
    		 <Html>
    			 <tpl for=".">
    				   <tpl if="amount &gt; 0">
    						  {numberCol}
    					</tpl>
    				   <tpl if="amount &ls; 0 || amount  == 0">
    						  0
    					</tpl>
    				 {amount}<br />
    				 {numberCol}<br />
    			 </tpl>
    		 </Html>
    	 </Template>
     </ext:TemplateColumn>
  3. #3
    Dear Baidaly

    It's work,Many thanks!!

    But i need to create another template column which has two datafields to do division calculation

    Would you kindly to give me a suggestion?
  4. #4
    If you just want to compare two date fields in the same record and render data in some way I recommend you Data Preparation: https://examples1.ext.net/#/GridPane.../Data_Prepare/

    But if you will have any problems or this approach will not work for your situation, just ask again :)
  5. #5
    It does not match my requirement, because i do not want to change the data source 's layout.
    I had try to use "Renderer" function,but it does not work
    
       <ext:TemplateColumn ColumnID="GK" Width="65px" Header="Percentage" Hidden="true" MenuDisabled="true">
                                                                <Template ID="Template2" runat="server">
                                                                    <Html>
                                                                    <tpl for=".">                    
                                                                    {BDMNG}+{MENGE}
                                                                     </tpl>
                                                                    </Html>
                                                                </Template>
                                                                <Renderer Fn="CalcGK" />
       </ext:TemplateColumn>
    
    js
    
                var template = '<a style="color:{0};">{1}</a>';
            var CalcGK = function(v1) {
    
    
    
                var index = v1.lastIndexOf("+");
    
    
                if (index > -1) {
                    var n1 = parseFloat(v1.substr(0, index));
                    var n2 = parseFloat(v1.substr(index + 1, v1.length - index - 1));
                    return String.format(template, "blue", (100 * n1 / n2).toFixed(2)+ "%");
    
    
                }
                else { return String.format(template, "red", "0%"); }
    
    
            };
    Last edited by dew3083142; Nov 01, 2012 at 6:07 AM.
  6. #6
    Confirmed,A TemplateColumn doesn't support a custom renderer.

    So i need to try other way...
  7. #7
    Hi,

    I think you can accomplish your Renderer logic using Template.

    It allows JavaScript and conditions.

    More details are here:
    https://examples1.ext.net/#/Miscella...late/Overview/
    http://docs.sencha.com/ext-js/3-4/#!...od-constructor
  8. #8
    It's work!
    Many tks!!

         <ext:TemplateColumn ColumnID="GK" Width="65px" Header="Percentage" Hidden="true" MenuDisabled="true">
                                                                <Template ID="Template2" runat="server">
                                                                    <Html>
                                                                    <tpl for=".">                    
                                                            <p>  {[(values.BDMNG*100/values.MENGE).toFixed(2)]}%</p>
                                                                     </tpl>
                                                                    </Html>
                                                                </Template>
                                                            </ext:TemplateColumn>

Similar Threads

  1. Adding Dropdown box to TemplateColumn of GridPanel
    By Mrityunjay in forum 2.x Help
    Replies: 0
    Last Post: Jun 19, 2012, 9:41 AM
  2. [CLOSED] TemplateColumn Click Not Registering
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 14, 2011, 12:24 PM
  3. [CLOSED] Embedding server tags in TemplateColumn
    By pj_martins in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 30, 2011, 1:39 PM
  4. [CLOSED] Renderer on a TemplateColumn: not working
    By capecod in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 11, 2010, 12:34 AM
  5. [CLOSED] Problem with TemplateColumn
    By xeo4.it in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 30, 2010, 10:19 AM

Tags for this Thread

Posting Permissions