[英]get whole data of all rows in which checkbox is checked in telerik grid through jquery and store it in array
I am using Telerik grid in MVC 3 and I have a grid having some columns, and each row has a checkbox. 我在MVC 3中使用Telerik网格,我有一个有一些列的网格,每行都有一个复选框。 On the submit of the Ok button I want all the data of the grid to be fetch, from the row in which the checkbox is checked.
在提交Ok按钮时,我希望从选中复选框的行中获取网格的所有数据。 I want to get records of each column to be stored in a separate array.
我想获取要存储在单独数组中的每列的记录。 And I want to do this using a jquery.
我想用jquery来做这件事。
What should I do for this? 我该怎么办?
I did something like this to get the count of checkboxes checked in a grid: 我做了类似这样的事情,以便在网格中检查复选框的数量:
function getData() {
debugger;
var Records = $(':checked');
var checkedRecords = Records.length - 2;
if (checkedRecords < 1) {
alert('Check a few checkboxes first.');
return checkedRecords;
}
else {
alert("RecordsChecked: " + checkedRecords);
}
}
getData()
is a function which will called on click of Ok button. getData()
是一个单击Ok按钮时调用的函数。
Please suggest me something... 请给我一些建议......
This is my Telerik grid code: 这是我的Telerik网格代码:
<% Html.Telerik().Grid<Model>()
.Name("TelerikGrid")
.ToolBar(toolbar => toolbar.Template(
Html.Resource("Grid")))
.DataKeys(keys =>
{
keys.Add(o => o.EmployeeID);
})
.Columns(columns =>
{
columns.Bound(m => m.EmployeeID)
.ClientTemplate("<input type='checkbox' name='Employee1' onclick='return function1(this);' id='Employee1' />")
columns.Bound(m => m.EmpFName).Title("F Name").ReadOnly(true).Width(65);
columns.Bound(m => m.EmpLName).Title("L Name").ReadOnly(true).Width(70);
columns.Bound(m => m.Task).Title("Task")
.ClientTemplate("<div id='textbox1'><input type='textbox' name='Task' id='Task' disabled='disabled' new { style='width:55px'} value='<#=Task#>' /></div>").Width(53);
})
.DataBinding(databinding => databinding
.Ajax()
.Select("GetData", "Home”)
)
.Selectable()
.Render();
%>
I don't think we understand each other. 我不认为我们彼此了解。 But I will give you an answer that works with a Telerik Grid rendered as a table.
但是我会给你一个与作为表格呈现的Telerik Grid一起使用的答案。 So suppose this is your grid:
所以假设这是你的网格:
<table cellspacing="0"><colgroup>
<col style="width:45px">
<col style="width:100px"><col style="width:200px"><col><col style="width:120px"></colgroup><tbody>
<tr><td><input type='checkbox' name='SelectedEmployee' id='SelectedEmployee' /></td><td>10248</td><td>Paul Henriot</td><td>59 rue de l'Abbaye</td><td>07/04/1996</td></tr>
<tr class="t-alt"><td><input type='checkbox' name='SelectedEmployee' id='SelectedEmployee' /></td><td>10249</td><td>Karin Josephs</td><td>Luisenstr. 48</td><td>07/05/1996</td></tr>
<tr><td><input type='checkbox' name='SelectedEmployee' id='SelectedEmployee' /></td><td>10250</td><td>Mario Pontes</td><td>Rua do Paço, 67</td><td>07/08/1996</td></tr>
<tr class="t-alt"><td><input type='checkbox' name='SelectedEmployee' id='SelectedEmployee' /></td><td>10251</td><td>Mary Saveley</td><td>2, rue du Commerce</td><td>07/08/1996</td></tr>
<tr><td><input type='checkbox' name='SelectedEmployee' id='SelectedEmployee' /></td><td>10252</td><td>Pascale Cartrain</td><td>Boulevard Tirou, 255</td><td>07/09/1996</td></tr>
<tr class="t-alt"><td><input type='checkbox' name='SelectedEmployee' id='SelectedEmployee' /></td><td>10253</td><td>Mario Pontes</td><td>Rua do Paço, 67</td><td>07/10/1996</td></tr>
</tbody></table>
So your grid has the following columns, in order, from left to right: 因此,您的网格按从左到右的顺序排列以下列:
id
of an employee - second column id
- 第二栏 name
of an employee - third column name
- 第三栏 Now to answer your question: 现在回答你的问题:
On the submit of the Ok button I want all the data of the grid to be fetch, from the row in which the checkbox is checked
在提交Ok按钮时,我希望从选中复选框的行中获取网格的所有数据
You can call a function that will build your array object in jquery like this: 你可以调用一个在jquery中构建数组对象的函数,如下所示:
function readGrid() {
var employees = [];
$('[name="SelectedEmployee"]:checked').each(function() {
var row = $(this).closest('tr');
var emp = {
// we start at 2 because the first one is the checkbox
// also it would be easier if you have an id for each of the column
// and do this row.find('#idCol') / row.find('#nameCol')
id: row.find('td:nth-child(2)').text(),
name: row.find('td:nth-child(3)').text(),
};
employees.push(emp);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.