Scott,
Nice job. I like the logic, and the fading out of unselected rows. My solution was, admittedly, a quick one. It certainly wouldn't scale past 1,000 rows or so -- especially with the majority # selected -- but if the 10/50 number is firm, seemed to work OK. --SEAN O Scott Sauyet-3 wrote: > > > Bob O wrote: >> Basically i have a YUI datatable and i want to use jQuery to hide all >> but a user generated number of rows that are random selected > > Something like this might be what you're looking for: > > http://jsbin.com/ozafa/edit > > The important part is this: > > var $rows = $("#myTable tbody tr"); > $("form").submit(function() { > var count = parseInt($("#count").val()); > var chosen = 0; > var total = $rows.length; > $rows.each(function(index) { > if (Math.random() < (count - chosen) / (total - index)) { > $(this).fadeIn("slow"); > chosen++; > } else { > $(this).fadeOut("slow"); > } > }); > return false; > }); > > This is different from the previous suggestion, which kept randomly > picking rows and if they weren't already chosen, added them to the list. > This solution iterates through the rows, updating the probability of > each one being chosen according to how many have already been chosen and > how many we still want to choose. It might be a bit less efficient for > 10 out of 50, but would probably be much more efficient at 40 out of 50, > and it is entirely predictable, in that it run exactly one random call > for each row in the table. > > Cheers, > > -- Scott > > -- View this message in context: http://www.nabble.com/show-hide-random-rows-tp22570300s27240p22584637.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.