0 Replies Latest reply on Aug 28, 2010 2:40 AM by mosamna

    passing html table as string with ampersand values problem.

    mosamna

      Hi there,

       

      I'm converting a datagrid table into a string having html table code inside then passing this string to an external ABAP html file.

      The problem is as follows: whenever an item having an ampersand like "I am a friend of Micheal&Alex"  the html file will show only this much  "I am a friend of Micheal" without the rest of the string.

       

      my code:

       

      private function convertDGToHTMLTable(dg:DataGrid):String {

       

       

       

           var font:String = dg.getStyle('fontFamily');

           var size:String = dg.getStyle('fontSize');

           var str:String = '';

           var colors:String = '';

           var style:String = 'style="font-family:'+font+';font-size:'+size+'pt;"';

           var hcolor:Array;

       

       

           //Retrieve the headercolor

           if(dg.getStyle("headerColor") != undefined) {

                hcolor = [dg.getStyle("headerColor")];

           } else {

                hcolor = dg.getStyle("headerColors");

           }

       

       

           //Set the htmltabel based upon knowlegde from the datagrid

           str+= '<table width="'+dg.width+'"><thead><tr width="'+dg.width+'" style="background-color:#' +Number((hcolor[0])).toString(16)+'">';

       

       

           //Set the tableheader data (retrieves information from the datagrid header

           for(var i:int = 0;i<dg.columns.length;i++) {

                colors = dg.getStyle("themeColor");

       

       

                if(dg.columns[i].headerText != undefined) {

                     str+="<th "+style+">"+dg.columns[i].headerText+"</th>";

                } else {

                     str+= "<th "+style+">"+dg.columns[i].dataField+"</th>";

                }

           }

       

           str += "</tr></thead><tbody>";

           colors = dg.getStyle("alternatingRowColors");

       

       

           //Loop through the records in the dataprovider and

           //insert the column information into the table

       

           for(var j:int =0;j<dg.dataProvider.length;j++) {

                str+="<tr width=\""+Math.ceil(dg.width)+"\">";

       

              

                for(var k:int=0; k < dg.columns.length; k++) {

       

                     //Do we still have a valid item?

                     if(dg.dataProvider.getItemAt(j) != undefined && dg.dataProvider.getItemAt(j) != null) {

       

                   

                          //Check to see if the user specified a labelfunction which we must

                          //use instead of the dataField

                          if(dg.columns[k].labelFunction != undefined) {

                               str += "<td width=\""+Math.ceil(dg.columns[k].width)+"\"                               "+style+">"+dg.columns[k].labelFunction(dg.dataProvider.getItemAt(j),dg.columns[k].dataFi eld)+"</td>";

                          } else {

                               //Our dataprovider contains the real data

                               //We need the column information (dataField)

                               //to specify which key to use.

                               str += "<td width=\""+Math.ceil(dg.columns[k].width)+"\" "+style+">"+dg.dataProvider.getItemAt(j)[dg.columns[k].dataField]+"</td>";

                          }

                     }

                }

                str += "</tr>";

           }

           str+="</tbody></table>";

           return str;

      }

       

       

       

      private function loadDGInExcel(dg:DataGrid):void {

       

           var htmltable:String = convertDGToHTMLTable(dg);

           htmltable = htmltable.replace(/&/g,"&amp;");

           var variables:URLVariables = new URLVariables("param1="+htmltable);

       

           //Setup a new request and make sure that we are

           //sending the data through a post

           var u:URLRequest = new URLRequest(link);

           u.method = URLRequestMethod.POST;

           navigateToURL(u,"_blank");

       

           u.data = variables; //Pass the variables

      }