0

I have a YUI datatable as follows

YAHOO.example.Data = {
        bookorders: [
            {id:"po-0167", date:new Date(1980, 2, 24), quantity:1, amount:4, title:"A Book About Nothing"},
            {id:"po-0783", date:new Date("January 3, 1983"), quantity:null, amount:12.12345, title:"The Meaning of Life"},
            {id:"po-0297", date:new Date(1978, 11, 12), quantity:12, amount:1.25, title:"This Book Was Meant to Be Read Aloud"},
            {id:"po-1482", date:new Date("March 11, 1985"), quantity:6, amount:3.5, title:"Read Me Twice"}
        ]
    }

and i added a subscribe event to it

myDataTable.subscribe("rowClickEvent", function(args){   
            alert("inside click1");

            var rec = myDataTable.getSelectedRows()[0];
            .
            .
            .
            printTitle(record.title);
        });

the problem is that i can't manage to get the selected row. i have another function printTitle to alert the title of the book on which the row was clicked.

I managed to get the selectedRow with the myDataTable.getSelectedRows()[0]. I updated my code, but now i cant seem to get the title.

jonleech
  • 461
  • 1
  • 6
  • 30

2 Answers2

1

I think you're close.

Try the following:

Please note that "var selectedRecordId = myDatatable.getSelectedRows()[0];" give you the id of the record. You may need to do "var selectedRecord = myDatatable.getRecord(id);" to get your record. When you have the record, you need to use "var title = selectedRecord.getData('title');" to get the title.

Check those docs (that helped me answering): http://developer.yahoo.com/yui/docs/YAHOO.widget.Record.html http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html

ludo
  • 374
  • 1
  • 9
  • I think i found the answer here http://stackoverflow.com/questions/3022436/call-click-event-on-last-clicked-row-in-yui-datatable – jonleech Sep 13 '12 at 05:45
  • the post there lead me to think of using the target to get the selected record thus using the selected Record and getting the data using getData("title"); – jonleech Sep 13 '12 at 05:45
  • 1
    Good, args.target looks like the way to do! I'm happy you found a solution. Using getSelectedRows()[0] to get id and the getRecord was not working? – ludo Sep 13 '12 at 06:34
  • i tried but it din't go. the getSelectedRows()[0] gives you a sort of record as getSelectedRows() gives you an array. so yea i tried but using the getData("title") on the record doesn't seem to yield me the title. – jonleech Sep 13 '12 at 07:03
1

was looking through the forums for more inspiration i stumbled upon this

another question on yui row click event

in the end i replaced the getselectedrows with

myDataTable.subscribe("rowClickEvent", function(args){   

            var record = this.getRecord(args.target);
            var title = record.getData("title");

            alert("inside click2 : " + title);

        });

and it works like a charm

Community
  • 1
  • 1
jonleech
  • 461
  • 1
  • 6
  • 30