dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: What's best way to call function with parameter from DATAGRID CLICKS?

  1. #1
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991

    What's best way to call function with parameter from DATAGRID CLICKS?

    I have a datagrid with 3 columns.. user_id, name, and age..

    i'd like it that when the user clicks on a row, it calls a function passing the parameter "user_id" to it... but as far as the documentation goes.. the click events for a DataGrid only returns the following:

    columnIndex A number that indicates the index of the column that was pressed. The first position is 0.

    itemIndex A number that indicates the index of the row that was pressed. The first position is 0.

    type The string "cellPress".
    any ideas?

  2. #2
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    anyone please?

  3. #3
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    Give datagrid component instance name "testGrid". Now if you use code like this:
    Code:
    testGrid.columnNames = ["user_id", "name", "age"];
    // Set up sample data.
    testGrid.dataProvider = [{user_id:123, name:"Clark", age:3135}, {user_id:321,name:"Bruce", age:403}, {name:"Peter", age:25, user_id:768947}];
    // Create listener object.
    var dgListener:Object = new Object();
    dgListener.cellPress = function(evt_obj:Object) {
    	var user_id=evt_obj.target.selectedItem.user_id;
    	trace(user_id);
    };
    // Add listener.
    testGrid.addEventListener("cellPress", dgListener);
    variable user_id in cellPress function will get value of column user_id from currently pressed row.

  4. #4
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    Wonderful! Thanks mate!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center