Skip to Content

Table control issue

Hello all,

I'm trying to get data from the database and fill a table control, but i cant seem to find a way to do it.

I can query the database and get the data, but for some reason it doesnt show up in the table control.

Its probably has something to do with the binding, but i have no clue what exactly.

Here is where i define the table control in the index.html

        var userIDColumnTemplate = new sap.ui.commons.TextField({
         value: "{ENUM}"
        });
        var nameColumnTemplate = new sap.ui.commons.TextField({
         value: "{ENAME}"
        });
        var cityColumnTemplate = new sap.ui.commons.TextField({
         value: "{ECITY}"
        });
        var phoneColumnTemplate = new sap.ui.commons.TextField({
         value: "{EPHONE}"
        });


        var oTable = new sap.ui.table.Table({
            title: "Employee Details",                                   // Displayed as the heading of the table
            visibleRowCount: 3,                                           // How much rows you want to display in the table
            selectionMode: sap.ui.table.SelectionMode.Single, //Use Singe or Multi
            navigationMode: sap.ui.table.NavigationMode.Paginator, //Paginator or Scrollbar
            enableColumnReordering:true,       // Allows you to drag and drop the column and reorder the position of the column
            width:"1024px",                              // width of the table
//			columns : [ 
//              {label: "ENUM", template: userIDColumnTemplate  },   
//              {label: "ENAME", template: nameColumnTemplate },
//              {label: "ECITY", template: cityColumnTemplate  },   
//              {label: "EPHONE", template: phoneColumnTemplate  }
//             ]
          });

        oTable.addColumn(new sap.ui.table.Column({
            label: new sap.ui.commons.Label({text: "ID"}),
            //template: new sap.ui.commons.TextView({text:"{lastName}"}),
            template: new sap.ui.commons.TextField().bindProperty("value","ENUM"),
            sortProperty: "ENUM",        // enables sorting on the column
            filterProperty: "ENUM",       // enables set filter on the column
            width: "125px"                  // width of the column
        }));


        oTable.addColumn(new sap.ui.table.Column({
            label: new sap.ui.commons.Label({text: "Name"}),
            //template: new sap.ui.commons.TextView({text:"{lastName}"}),
            template: new sap.ui.commons.TextField().bindProperty("value","ENAME"),
            sortProperty: "ENAME",        // enables sorting on the column
            filterProperty: "ENAME",       // enables set filter on the column
            width: "125px"                  // width of the column
        }));


        oTable.addColumn(new sap.ui.table.Column({
            label: new sap.ui.commons.Label({text: "City"}),
            //template: new sap.ui.commons.TextView({text:"{lastName}"}),
            template: new sap.ui.commons.TextField().bindProperty("value","ECITY"),
            sortProperty: "ECITY",        // enables sorting on the column
            filterProperty: "ECITY",       // enables set filter on the column
            width: "125px"                  // width of the column
        }));


        oTable.addColumn(new sap.ui.table.Column({
            label: new sap.ui.commons.Label({text: "Phone"}),
            //template: new sap.ui.commons.TextView({text:"{lastName}"}),
            template: new sap.ui.commons.TextField().bindProperty("value","EPHONE"),
            sortProperty: "EPHONE",        // enables sorting on the column
            filterProperty: "EPHONE",       // enables set filter on the column
            width: "125px"                  // width of the column
        }));

This is the that get the data from the database and the json (Which i stole from some post in the forums)

function escapeSpecialChars(input) {
          if(typeof(input) !== 'undefined' && input !== null)
          {
            return input
            .replace(/[\\]/g, '\\\\')
            .replace(/[\"]/g, '\\\"')
            .replace(/[\/]/g, '\\/')
            .replace(/[\b]/g, '\\b')
            .replace(/[\f]/g, '\\f')
            .replace(/[\n]/g, '\\n')
            .replace(/[\r]/g, '\\r')
            .replace(/[\t]/g, '\\t'); }
          else{
            return "";
          }
}

/**
@function Converts any XSJS RecordSet object to a JSON Object
@param {object} rs - XSJS Record Set object
@param {optional String} rsName - name of the record set object in the JSON
@returns {object} JSON representation of the record set data
*/

function recordSetToJSON(rs,rsName)
{
          rsName = typeof rsName !== 'undefined' ? rsName : 'entries';
          var meta = rs.getMetaData();
          var colCount = meta.getColumnCount();
          var values = [];
          var table = [];
          var value = "";


          while (rs.next()) {


          for (var i = 1; i <= colCount; i++) {
                value = '"' + meta.getColumnLabel(i) + '" : ';
               switch(meta.getColumnType(i)) {


               case $.db.types.VARCHAR:


               case $.db.types.CHAR:
                    value += '"' + escapeSpecialChars(rs.getString(i)) + '"';
                    break;
               case $.db.types.NVARCHAR:


               case $.db.types.NCHAR:


               case $.db.types.SHORTTEXT:
                    value += '"' + escapeSpecialChars(rs.getNString(i)) + '"';
                    break;
               case $.db.types.TINYINT:


               case $.db.types.SMALLINT:


               case $.db.types.INT:


               case $.db.types.BIGINT:
                    value += rs.getInteger(i);
                    break;
               case $.db.types.DOUBLE:
                    value += rs.getDouble(i);
                    break;
               case $.db.types.DECIMAL:
                    value += rs.getDecimal(i);
                    break;
               case $.db.types.REAL:
                    value += rs.getReal(i);
                    break;
               case $.db.types.NCLOB:
               case $.db.types.TEXT:
                    value += '"' + escapeSpecialChars(rs.getNClob(i)) + '"';
                    break;
               case $.db.types.CLOB:
                    value += '"' + escapeSpecialChars(rs.getClob(i)) + '"';
                    break;                   
               case $.db.types.BLOB:
                          value += '"' + $.util.convert.encodeBase64(rs.getBlob(i)) + '"';
                    break;                   
               case $.db.types.DATE:
                    value += '"' + rs.getDate(i) + '"';
                    break;
               case $.db.types.TIME:
                    value += '"' + rs.getTime(i) + '"';
                    break;
               case $.db.types.TIMESTAMP:
                    value += '"' + rs.getTimestamp(i) + '"';
                    break;
               case $.db.types.SECONDDATE:
                    value += '"' + rs.getSeconddate(i) + '"';
                    break;
               default:
                    value += '"' + escapeSpecialChars(rs.getString(i)) + '"';
               }
               values.push(value);
               }
             table.push('{' + values + '}');
          }
          return JSON.parse('{"' + rsName + '" : [' + table          + ']}');
}


        var query = "select * from EMPLOYEE";


        var conn = $.db.getConnection();
        var pstmt = conn.prepareStatement(query);


        var rs = pstmt.executeQuery();


        var jsonOut = recordSetToJSON(rs, "EMPLOYEE");
        pstmt.close();


        conn.close();


        $.response.status = $.net.http.OK;
        $.response.contentType = "application/json";
        $.response.setBody(JSON.stringify(jsonOut));

Could anyone advice?

Thank you.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers