Bootstrap-table: How to get selected rows from Bootstrap table

Created on 3 Aug 2015  路  20Comments  路  Source: wenzhixin/bootstrap-table

Hi guys,
I want to do some processing on the selected rows which user selects from bootstrap table. I want to get the data and then fire one script from using the selected rows.
Please help.

Lovelesh.

help-wanted

Most helpful comment

Hi,I think u need this:
$(function () {
$button.click(function () {
alert($table.bootstrapTable('getSelections').length);
});
});

All 20 comments

Have you checked out the documentation: http://bootstrap-table.wenzhixin.net.cn/documentation/#methods?

Hi Guys,
Thanks for the help.
The complete problem statement is below:
I have a table which shows machine endpoints and names, below that I have one text field in which user provides some input, below that there is a button to GO. What I need is that on that button click, the mentioned action in text fields would be performed on selected machines. I have the script in background that do the job, but I need to save all the data provided by user into a JSON and then fire the script.
I am trying to do this in the code for controller, on the button click I am calling a method and then in that method I wish to do all the job. But I am not able to get the selected rows values into that method.
image

Can I use getSelections in that controller file? If yes, is there any example?

Lovelesh.

Hey guys,
I know that you guys are very busy, but request you to please help!! I am completely stuck at this point now. If anyone can post an example for step by step usage of selected rows.

Lovelesh.

I want the functionality like below:
Case: Like in .Net, we mention few html elements in aspx file, then user provide some data, and on button click we mention the corresponding method in onclick of that button, then that method is defined in c# file.

Just like this, I want the selected rows data and text field data to get processed.
Where should I do this job? In controller file or in the same erb file?

Lovelesh.

You can check out our examples site: http://issues.wenzhixin.net.cn/bootstrap-table/, I think that can be help.

Hi man, thanks for the reply. Sorry to say but examples there are just not like user guide. I am very new to ror and bootstrap. I am still in stuck state, and now I need a step by step guide, which tell me like go to this file, do this and this. The examples there are like you go and done. No steps to reproduce. :(
Everywhere I search on google, they mention four CRUD methods, what if I do not want to create,retrieve,update or delete and entry. What I need is just to call a method server side written in my controller file.
As I mentioned my issue in above content, I request you to provide an step by step tutorial.
Please help.

Lovelesh.

Hi guys,
I am urging you guys to help me on this. Please reply with some step by step example.

Lovelesh.

My main question is as below: Below are the files: routes.rb:

get 'service_action/test' => 'service_actions#show'
post 'service_action/test' => 'service_actions#test'
test.html.erb

<%= form_tag("/service_action/test", :method=>"post") do %>
<%= text_field_tag(:todo_text) %>
<%= select_tag(:ddl3, options_for_select([["Windows","1"],["RHEL","2"],["ALL","3"]]), class: 'form-control')%>
<%= submit_tag("Add todo", :class=>"btn") %>











Machine Name DNS Name Server Type Platform

<% end %>
controller.rb:

def test
mkdir c:\\opt\\CreateJSON\\#{params[:todo_text]}
mkdir c:\\opt\\CreateJSON\\#{params[:ddl3]}
render 'test'
end
def show
render 'test'
end
My question is: "I can access the textfield(todo_text) and select_tag(ddl3) values in my controller method as you can see, but I am not able to access the selected values from the table included. It is table in which I display some info to user and user select n number of rows from this table. I need the selected rows too from the view back to my controller method."

stackoverflow reference is: http://stackoverflow.com/questions/31855576/ruby-on-rails-call-a-conroller-method-from-view-button-click-and-access-view-htm.
Please help me on this, as no one on net also know how to get bootstrap table selected rows to the controller method.

Also just for an info, when I am trying to replicate example from http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html#basic-events-table, I am not able to view that div section in green, which is there in example to show the result. Any idea on this please?

Only got a few seconds, but you can get the selected rows using getSelections() method (http://bootstrap-table.wenzhixin.net.cn/documentation/#methods) and then just use jquery ajax (http://www.w3schools.com/jquery/ajax_ajax.asp, http://www.sitepoint.com/use-jquerys-ajax-function/) to pass it through to wherever you wanted, adding it to the data index of the request.

http://issues.wenzhixin.net.cn/bootstrap-table/#methods/getSelections.html

Hi Dabros,
Thanks a lot for looking into it. I am trying to get something from examples, but as I mentioned early, I am very new to ror and ajax. So I am feeling very confused using the examples, also I have searched internet a lot for a end-to-end working example of my case, but found nothing. :(
Can you please provide me an working end-to-end example.

thats what the examples are - just use 'view source' or (even better) the 'view on github' button to see the source code for any example.

For jquery ajax, there are so many dozens and dozens of great tutorials out there - the selected rows are just another object/array variable at that point.

Hmm I am going to do it using a new project and try to do as required. Will keep this thread posted about results.
Thanks for looking into it.

You can view the source code here: https://github.com/wenzhixin/bootstrap-table-examples/blob/master/methods/getSelections.html
It is very simple: $('#table').bootstrapTable('getSelections')

Thanks wenzhixin, I am working on it. Will post the update.

Hello I have problems with width colmn radio
radiobutton

@LuisAlejandroDuarte - please see https://github.com/wenzhixin/bootstrap-table/blob/master/CONTRIBUTING.md#using-the-issue-tracker and follow guidelines there

This should really be new issue since this one is closed, just include #1244 in your post and it will link to here for referance.

In new issue, at minimum we need:

  1. Clear expected output vs actual output
  2. Explanation of steps you tried to fix this already
  3. A fiddle showing this issue, screeshots do not suffice

Then we can help you, because as is this is in wrong place and I have absolutely no idea what you actually need or were expecting.

Thanks

Hi,I think u need this:
$(function () {
$button.click(function () {
alert($table.bootstrapTable('getSelections').length);
});
});

Was this page helpful?
0 / 5 - 0 ratings

Related issues

havok2063 picture havok2063  路  39Comments

typo3ua picture typo3ua  路  23Comments

Valery1991 picture Valery1991  路  31Comments

iamthestreets picture iamthestreets  路  26Comments

startovernow picture startovernow  路  13Comments