Highlighted

Binding a cfgrid to a cfc throws js error when the cfc returns an empty dataset in CF 2016

New Here ,
Nov 10, 2016

Copy link to clipboard

Copied

I'm having a problem in CF 2016 with a grid I'm trying to populate with a bound cfc method.  If my method returns no data, I get a JavaScript error: ext-all.js:18 Uncaught TypeError: Cannot read property 'id' of undefined(…).  However, this code executes fine in CF 9.

Is this a bug?  Or should I be doing something different in CF 2016 to handle a method that returns no data?

My exact version is 2016.0.0.298074.

Below is the code I'm testing with.  First, the page with the cfgrid:

<cfajaximport tags="cfform,cfpod,cfdiv,cfgrid" />

<h1>Invoke method</h1>

<cfinvoke component="data" method="getColors" returnvariable="qColors">

<cfdump var="#qColors#" label="invoked method">

<h1>Bind method</h1>

<cfform id="frmColors">
     <cfgrid name="grdColors" format="html" pagesize="5"
          bind="cfc:data.getColorsRemote({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">

          <cfgridcolumn name="COLOR" header="Color" width="300">
          <cfgridcolumn name="ALT" header="Spanish" width="300">
     </cfgrid>
</cfform>

And this is the component: data.cfc

<cfcomponent output="false" displayname="data">

     <cffunction name="getColors" access="public" returntype="query" output="false">
          <cfset var q = 0>
          <cfset qColors = getDataSet()>
          <cfquery dbtype="query" name="q">
               SELECT COLOR, ALT FROM qColors
                    ORDER BY COLOR ASC
          </cfquery>
          <cfreturn q>
     </cffunction>

     <cffunction name="getColorsRemote" access="remote" returntype="struct" output="false">
          <cfargument name="page" type="numeric" required="true">
          <cfargument name="pageSize" type="numeric" required="true">
          <cfargument name="gridSortColumn" type="string" required="false" default="">
          <cfargument name="gridSortDir" type="string" required="false" default="">

          <cfparam name="arguments.gridSortColumn" default="COLOR">
          <cfparam name="arguments.gridSortDirection" default="ASC">

          <cfset var q = 0>

          <cfset qColors = getDataSet()>
          <cfquery dbtype="query" name="q">
               SELECT COLOR, ALT FROM qColors
                    <cfif arguments.gridSortColumn NEQ "" AND arguments.gridSortDir NEQ "">
                         ORDER BY #arguments.gridSortColumn# #arguments.gridSortDir#
                    </cfif>
          </cfquery>

          <cfreturn queryConvertForGrid(q, arguments.page, arguments.pageSize)>
     </cffunction>

     <cffunction name="getDataSet" access="private" returntype="query" output="false">
          <!--- create dataset --->
          <cfset qColors = queryNew("COLOR, ALT","VarChar, VarChar")>

          <!--- comment out this section to simulate no data --->

          <cfset newRow = queryAddRow(qColors, 7)>
          <cfset temp = querySetCell(qColors, "COLOR", "Red", 1)>
          <cfset temp = querySetCell(qColors, "ALT", "Rojo", 1)>
          <cfset temp = querySetCell(qColors, "COLOR", "Orange", 2)>
          <cfset temp = querySetCell(qColors, "ALT", "Naranja", 2)>
          <cfset temp = querySetCell(qColors, "COLOR", "Yellow", 3)>
          <cfset temp = querySetCell(qColors, "ALT", "Amarillo", 3)>
          <cfset temp = querySetCell(qColors, "COLOR", "Green", 4)>
          <cfset temp = querySetCell(qColors, "ALT", "Verde", 4)>
          <cfset temp = querySetCell(qColors, "COLOR", "Blue", 5)>
          <cfset temp = querySetCell(qColors, "ALT", "Azul", 5)>
          <cfset temp = querySetCell(qColors, "COLOR", "Indigo", 6)>
          <cfset temp = querySetCell(qColors, "ALT", "Indigo", 6)>
          <cfset temp = querySetCell(qColors, "COLOR", "Violet", 7)>
          <cfset temp = querySetCell(qColors, "ALT", "Violeta", 7)>

          <!--- end comment --->

          <cfreturn qColors>
     </cffunction>

</cfcomponent>

Views

330

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Binding a cfgrid to a cfc throws js error when the cfc returns an empty dataset in CF 2016

New Here ,
Nov 10, 2016

Copy link to clipboard

Copied

I'm having a problem in CF 2016 with a grid I'm trying to populate with a bound cfc method.  If my method returns no data, I get a JavaScript error: ext-all.js:18 Uncaught TypeError: Cannot read property 'id' of undefined(…).  However, this code executes fine in CF 9.

Is this a bug?  Or should I be doing something different in CF 2016 to handle a method that returns no data?

My exact version is 2016.0.0.298074.

Below is the code I'm testing with.  First, the page with the cfgrid:

<cfajaximport tags="cfform,cfpod,cfdiv,cfgrid" />

<h1>Invoke method</h1>

<cfinvoke component="data" method="getColors" returnvariable="qColors">

<cfdump var="#qColors#" label="invoked method">

<h1>Bind method</h1>

<cfform id="frmColors">
     <cfgrid name="grdColors" format="html" pagesize="5"
          bind="cfc:data.getColorsRemote({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">

          <cfgridcolumn name="COLOR" header="Color" width="300">
          <cfgridcolumn name="ALT" header="Spanish" width="300">
     </cfgrid>
</cfform>

And this is the component: data.cfc

<cfcomponent output="false" displayname="data">

     <cffunction name="getColors" access="public" returntype="query" output="false">
          <cfset var q = 0>
          <cfset qColors = getDataSet()>
          <cfquery dbtype="query" name="q">
               SELECT COLOR, ALT FROM qColors
                    ORDER BY COLOR ASC
          </cfquery>
          <cfreturn q>
     </cffunction>

     <cffunction name="getColorsRemote" access="remote" returntype="struct" output="false">
          <cfargument name="page" type="numeric" required="true">
          <cfargument name="pageSize" type="numeric" required="true">
          <cfargument name="gridSortColumn" type="string" required="false" default="">
          <cfargument name="gridSortDir" type="string" required="false" default="">

          <cfparam name="arguments.gridSortColumn" default="COLOR">
          <cfparam name="arguments.gridSortDirection" default="ASC">

          <cfset var q = 0>

          <cfset qColors = getDataSet()>
          <cfquery dbtype="query" name="q">
               SELECT COLOR, ALT FROM qColors
                    <cfif arguments.gridSortColumn NEQ "" AND arguments.gridSortDir NEQ "">
                         ORDER BY #arguments.gridSortColumn# #arguments.gridSortDir#
                    </cfif>
          </cfquery>

          <cfreturn queryConvertForGrid(q, arguments.page, arguments.pageSize)>
     </cffunction>

     <cffunction name="getDataSet" access="private" returntype="query" output="false">
          <!--- create dataset --->
          <cfset qColors = queryNew("COLOR, ALT","VarChar, VarChar")>

          <!--- comment out this section to simulate no data --->

          <cfset newRow = queryAddRow(qColors, 7)>
          <cfset temp = querySetCell(qColors, "COLOR", "Red", 1)>
          <cfset temp = querySetCell(qColors, "ALT", "Rojo", 1)>
          <cfset temp = querySetCell(qColors, "COLOR", "Orange", 2)>
          <cfset temp = querySetCell(qColors, "ALT", "Naranja", 2)>
          <cfset temp = querySetCell(qColors, "COLOR", "Yellow", 3)>
          <cfset temp = querySetCell(qColors, "ALT", "Amarillo", 3)>
          <cfset temp = querySetCell(qColors, "COLOR", "Green", 4)>
          <cfset temp = querySetCell(qColors, "ALT", "Verde", 4)>
          <cfset temp = querySetCell(qColors, "COLOR", "Blue", 5)>
          <cfset temp = querySetCell(qColors, "ALT", "Azul", 5)>
          <cfset temp = querySetCell(qColors, "COLOR", "Indigo", 6)>
          <cfset temp = querySetCell(qColors, "ALT", "Indigo", 6)>
          <cfset temp = querySetCell(qColors, "COLOR", "Violet", 7)>
          <cfset temp = querySetCell(qColors, "ALT", "Violeta", 7)>

          <!--- end comment --->

          <cfreturn qColors>
     </cffunction>

</cfcomponent>

Views

331

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 10, 2016 0

Have something to add?

Join the conversation