• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Setting initial selection in <cfgrid>?

New Here ,
Nov 05, 2018 Nov 05, 2018

Copy link to clipboard

Copied

I am trying unsuccessfully to create a <cfgrid> (ColdFusion 9) with an initial selection and I can't seem to get it to work.  Note this could be none, some, or all of the rows.

There doesn't seem to be an option to easily to this.  I looked at the selectOnLoad attribute, but that will only select the first element.

I then looked at the onload attribute.  I created a JavaScript function but calls to ColdFusion.Grid.getGridObject('mygrid) are returning null in it. It appears that this is still too early in the process (although this seemed like exactly what I wanted).

I then tried registering my own event listener with

     ColdFusion.Event.registerOnLoad(initializeGrid,null,false,true);

This seemed to be better. I could actually select my rows (and see the selection), but they were immediately unselected by what I assume was some sort of refresh at the end of the load. So this is close, but still doesn't seem to happen after the grid is completely loaded.

This seems to be something people would like to do, but I have been unable to find any examples.

Any ideas?

Thanks!

Views

337

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
community guidelines
LEGEND ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Are there any JavaScript errors appearing in the console?  It might be a JS issue.

Just a thought.

V/r,

^ _ ^

Votes

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
community guidelines
New Here ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Yeah, I checked the console log and saw no JS errors. I should have mentioned that.

Votes

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
community guidelines
LEGEND ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Is the project you're working on available to us to view?

V/r,

^ _ ^

Votes

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
community guidelines
New Here ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Not currently, although I will try to make a simple test case that exhibits the problem.

But even without that, I haven't seen any way to initialize the selection in the grid (other than the first item).  No documentation either. 

Have you ever done it?

Votes

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
community guidelines
LEGEND ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

I've been coding CF since 2000, and I've never used CFGRID.  Sorry.  Just trying to be helpful, though.  I'ma read up on it.

V/r,

^ _ ^

UPDATE: Ah, that's why I've never used CFGRID - it has to be contained within a CFFORM, and I _NEVER_ use CFFORM for anything.

But I might still be able to help, if you get an online version of the issue for us to view.

Votes

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
community guidelines
New Here ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

So here's a stripped down example that exhibits this problem. In this example I am using the onload attribute to call a JS function in order to select items in the grid.  However, the call to getGridObject returns undefined.

<cfset q = queryNew("id,name")>

<cfloop index="x" from="1" to="10">

    <cfset queryAddRow(q)>

    <cfset querySetCell(q, "id", x)>

    <cfset querySetCell(q, "name", "Name #x#")>

</cfloop>

<script type="text/javascript">

    function selectItems(start, end) {

        var grid = ColdFusion.Grid.getGridObject('SelectStuff');

        var model = grid.getSelectionModel();

        model.selectRange(start, end, true);

    }

</script>

<cfform name="mytest" method="POST">

    <cfgrid name="SelectStuff" query="q" format="html" multirowselect="true" selectonload="no" onload="selectItems(2, 5)"></cfgrid>

</cfform>


Note that if you remove the onload attribute the grid loads just fine.

Votes

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
community guidelines
LEGEND ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

LATEST

Okay, I don't know if this will help, or not, but I found this link and it's not using ColdFusion.Grid.getGridObject, it's using Ext.grid.Grid.  Maybe that's the issue?

HTH,

^ _ ^

Votes

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
community guidelines
Resources
Documentation