[ 3 posts ]

Exbi

  • Username: Exbi
  • Joined: Sun Sep 04, 2011 8:55 am
  • Posts: 10
  • Location: Hampshire
  • Offline
  • Profile

Datatable - find all rows selected and perform an action?

Post Posted: Mon Sep 26, 2011 11:40 pm
+0-
Hi, I've got some code that updates a single selected row in a datatable. I'm finding out the selected row using the following code -

Code:
function updateRows() {
            var recordID = myDataTable_current.getSelectedRows()[0],
            record = myDataTable_current.getRecord(recordID);
            var myRecord = record.getData("id");


And then i run this to update that specific row in the database -

Code:
var putXML = YAHOO.util.connect.asyncRequest("PUT", "http://192.168.1.2:3000/egtable/" + myRecord + "/egvalue");


My question is...my datatable allows multiple rows to be selected...how would I run this code for every row selected rather than just the first selected row? I've spent a long time trying a few different things, but can't find any simple examples on performing an action on multiple rows.

Could anyone give me a quick example of how it would be done?

Thanks

Todd Smith

YUI Contributor

  • Username: stlsmiths
  • Joined: Thu Nov 05, 2009 10:03 am
  • Posts: 675
  • GitHub: stlsmiths
  • Gists: stlsmiths
  • IRC: t_smith
  • Offline
  • Profile

Re: Datatable - find all rows selected and perform an action

Post Posted: Tue Sep 27, 2011 9:48 am
+1-
The DataTable function you use in your updateRows function uses the method .getSelectedRows on your assignment at "var recordID = myDataTable_current.getSelectedRows()[0]". The .getSelectedRows method returns an array of selected rows, it actually returns the record DOM id elements. See http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html#method_getSelectedRows for the method API documentation.

The way you use it above is you are only using the first element, with the "[0]" index. You can simply loop over each element of this Array and access each individual element of the array to get the record to process it however you desire.

For some alternative methods of selecting records, specifically using "checkboxes" I highly recommend Satyam's example at http://www.satyam.com.ar/yui/#deleteRowsBy. Satyam's site is a wonderful resource for "all things DataTable", you should review his examples very carefully.

Additionally, I worked up a simpler example of multi-selecting rows using either checkboxes or row select some time ago, it is at http://blunderalong.com/pub/dt_select.html.

Todd

Exbi

  • Username: Exbi
  • Joined: Sun Sep 04, 2011 8:55 am
  • Posts: 10
  • Location: Hampshire
  • Offline
  • Profile
Tags:

Re: Datatable - find all rows selected and perform an action

Post Posted: Wed Sep 28, 2011 3:24 am
+0-
Thanks alot for the info Todd, I've managed to get it working perfectly using your example on - http://blunderalong.com/pub/dt_select.html

Much appreciated.
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum