如何从 YUI 数据表中获取所选行的内容?

发布于 2024-08-24 00:13:31 字数 108 浏览 5 评论 0 原文

我正在尝试获取 YUI 数据表中一行单元格的内容。

我可以使用 myDataTable.getSelectRows()[0] 来获取第一个选定的行。但是,如何获取该行第一个单元格的内容?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

汐鸠 2024-08-31 00:13:31

看起来 getSelectRows() 返回一个记录 ID 数组。您可以使用 getRecord() 检索相应的记录。获得记录后,使用 getData() 检索您感兴趣的字段的值。

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

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

丑疤怪 2024-08-31 00:13:31

我想我可能已经为你找到了答案,假设你自己还没有找到答案。

我有一个带有数据表和文本区域字段的相同类型的页面,当您在数据表中选择一行时,调用同一页面会显示文本区域字段中所选行的更多详细信息,并保留对所选行的选择。

1:为此,我应用以下名为 AllMyBroadcasts... 的示例 MySQL 查询

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

tblBroadcasts 表具有字段:日期、叙述、ID

2:然后,我在 HTML 超链接标记内向 YUI 数据表的表行提供以下内容。

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

3: 当单击 href 时,MyPage 会使用附加参数重新加载 SelectedBroadcastID 名为 MySlectedBroadcast 的查询中使用 SelectedBroadcastID ,这是一个简单的查询,用于输出 ID = SelectedbordcastID 的所有字段,然后在我的文本区域字段中显示所选行的叙述。

我在第二个 执行以下操作:

$SelectedRowID = 0;
if( isset($_GET['RowNumber'])) {
$SelectedRowID = $_GET['行号'];
上面

我把我的两个查询的代码放在了后面。

4:最后,为了让数据表选择所选行的行,我将以下内容添加到数据表脚本的 var yuidatdatable 部分...

yuidatatable1.select(yuidatatable1.getRow());

步骤 2 中提到的 -1 值作为一种解决方法,因为 yuidatatable 在 0 基数上工作,而步骤 1 中提到的 MySQL 在 1 基数上工作。

就这样吧!

也许有更好的理由使用 YUIDatatable 脚本中的 get ,很高兴知道是否是这样。也就是说,这对我来说效果很好,也许如果您还没有找到答案,我希望这会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文