jquery easyui datagrid getSelections用法
1.datagrid、 數(shù)據(jù)綁定
??? $('#tt').datagrid({
??????????????? url: 'GetDataJosn',
??????????????? title: 'DataGrid',
??????????????? width: 800,
??????????????? height: 300,
??????????????? pageSize: 10,
??????????????? idField: 'productid',
??????????????? fitColumns: true,
??????????????? nowrap: false,
??????????????? columns: [[
???????????? ?{ field: 'productid', title: 'Product ID', width: 100,checbox:true,
??????????????formatter:function(value,rec){
?????????????//返回一個需要table html代碼這個里面有個checkbox類型數(shù)據(jù)行
??????????????return?? GetTableHTML(rec.productid,rec.itemid);
?????????????}
????????????? },
??????????????{ field: 'itemid', title: 'Item ID', width: 80 },
??????????????{ field: 'listprice', title: 'List Price', width: 80, align: 'right'}
???????????? ]],
??????});
2.獲取選擇的checkbox行
?
??? function Getcheckbox() {
??????????
??????????? var ids = [];
??????????? var rows = $('#tt').datagrid('getSelections');
????????????//獲取datagrid選中行
??????????? for (var i = 0; i < rows.length; i++) {
???????????????? //獲取自定義table 的中的checkbox值
??????????????????? var k = document.getElementById(rows[i].productid).getElementsByTagName("input");
??????????????????? for (var m = 0; m < k.length; m++) {
??????????????????????
??????????????????????????????????????????? if( k[m].type.toLowerCase()?? =="checkbox"){
??????????????????????????????????????????????????????????????? if (k[m].checked) {
????????????????????????????????????????????????????????????????? ids.push(k[m].value);
??????????????????????????????????????????????????????????? }
??????????????????????????????????????????? }
????????????????????????????? }
??????????
????????????????????????? }
????????????????????????? return ids.join(',');
??????????? }
?3,以上就是jquery datagrd 的selections方法了應用,需要注意點兩點:
???? 1.數(shù)據(jù)返回的json 數(shù)據(jù)必須屬性必須綁定數(shù)據(jù)字段一致
??? 2.如果你選中數(shù)據(jù)有多行, 但是返回的rows.length =1,先看你的datagrid是否有idField如果沒有這個值,是無法完成這個方法,如果不是這個問? 題,那就你返回的數(shù)據(jù)有問題,是這個idField綁定值不唯一,確定你數(shù)據(jù)就可以搞定
?
轉載于:https://www.cnblogs.com/linsu/archive/2011/11/06/2238323.html
總結
以上是生活随笔為你收集整理的jquery easyui datagrid getSelections用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jq select操作全集
- 下一篇: [Tyvj1114 搭建双塔]