sana
sana

Reputation: 460

Showing a dynamic table in GSP where column & data comes at run time

getting two arrays from controller and code is -- Sql db = new Sql(dataSource_wldb1) // Create a new instance of groovy.sql.Sql with the DB of the Grails app def ivrColumns = []

                    db.eachRow(ivrColumnsQuery) {
                        rsRow ->
                            ivrColumns.add(rsRow.name)  }

                    def ivrResults = []
                    db.eachRow(mssqlQuery) {rows ->
                        //print rows
                        ivrResults.add(rows)
                    }

one has all column names & other has all row data.as below- return render(view:'xref',model:[ivrcolumns:ivrColumns,ivrresults:ivrResults] )

getting data in below format- Columns [ClientKey, Abbr, ConfigKey, Federal, State, DMA, Internal, Wireless, CRssing, CurfewExemption, CampaignID]

Data [groovy.sql.GroovyResultSetExtension@12f8d75, groovy.sql.GroovyResultSetE oovy.sql.GroovyResultSetExtension@12f8d75, groovy.sql.GroovyResultSetExtension@1 roovyResultSetExtension@12f8d75, groovy.sql.GroovyResultSetExtension@12f8d75, gr tSetExtension@12f8d75, groovy.sql.GroovyResultSetExtension@12f8d75, groovy.sql.G ion@12f8d75, groovy.sql.GroovyResultSetExtension@12f8d75]

view code is---

<g:if test="${ivrcolumns != null }">
<center>Database Location - WLDB1      <br>DB Name - IVR_GUARDIAN  </center><br><br>
<table class="table loadTable" >

    <thead>
            <tr bgcolor="#f0f0f0" >

    <g:each in="${ivrcolumns}" status="ii" var="columnivr">
    <td nowrap>${columnivr}</td>
    </g:each>       
            </tr>
    </thead>
    <tbody>
    <g:each in="${ivrresults}" status="jj" var="hed">

                    <tr>               
                            <g:each in="${ivrcolumns}" status="kk" var="col">       
                                    <td nowrap>${hed.col}</td>  ///please suggest how    to do it.
                            </g:each>
                    </tr>
    </g:each>


    </tbody>
</table>

now want to show in GSP page .i am able to display the column but having hard time to display data.not getting how the dot will be used to get correct data to each column.

Will appreciate any help.

thanks

Upvotes: 1

Views: 4168

Answers (1)

Tomas Lin
Tomas Lin

Reputation: 3532

Assuming that's just a sql result, you can just call ${ hed[ col ] } or ${ hed."$col" }

Upvotes: 1

Related Questions