开发者

How do I get the contents of a selected row from a YUI datatable?

I'm trying to get the contents of a cell in a row in a YUI datatable.

I can use myDataTable.getSelectRows()[开发者_JAVA百科0] to get the first selected row. However, how do I get the contents of the first cell in that row?


It looks like getSelectRows() returns an array of record IDs. You can retrieve the corresponding record using getRecord(). Once you have a record, use getData() to retrieve the value of the field you are interested in.

var recordID = myDataTable.getSelectRows()[0],
    record = myDataTable.getRecord(recordID);
console.log(record.getData("myField"));

http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html#method_getRecord http://developer.yahoo.com/yui/docs/YAHOO.widget.Record.html#method_getData


I think I may have the answer for you assuming you have not already found it yourself.

I have the same kind of page with a datatable and a textarea field, when you select a row in the datatable calls the same page displays further detail from the selected row in the textarea field and retains selection of the selected row.

1: To do this I apply the following example MySQL query called AllMyBroadcasts...

SELECT @rownum :=@rownum + 1 RowNumber, p.* FROM tblBroadcasts p, (SELECT @rownum := 0)r ORDER BY Date DESC

the tblBroadcasts table has fields : Date, Narrative, ID

2: I then provide the following to the table row of my YUI Datatable within HTML hyperlink tags.

href="MyPage.php?SelectedBroadcastID=' .$row_Broadcasts['ID'].'&RowNumber=' .($row_Broadcasts['RowNumber'] -1 )

3: When the href is clicked MyPage reload with additional parameters SelectedBroadcastID and RowNumber the SelectedBroadcastID I use in a second query against tblBroadcasts called MySlectedBroadcast which a simple query on outputting all fields where the ID = SelectedbordcastID. I then to my field to display the narrative of my selected row in my textarea field.

The second paramater I do the following with.

$SelectedRowID = 0; if( isset($_GET['RowNumber'])) { $SelectedRowID = $_GET['RowNumber']; }

Above I placed just after code covering my two queries.

4: Then finally to get the datatable to select the row of the selected row I include the following to the var yuidatdatable section of the datatable script...

yuidatatable1.select(yuidatatable1.getRow());

The -1 value referred to step 2 serves as a work around to fact that yuidatatable works on a 0 base and the MySQL referred to in step 1 on a 1 base.

There you go !

Perhaps there is a better why using get from within YUIDatatable scripting, be nice to know if so. That said this work fine for me and perhaps if you have not found an answer I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜