From 5d8b9b4d93a33a2ef753f608f6db8bcff8d2fb69 Mon Sep 17 00:00:00 2001 From: LiuXiaoping Date: Tue, 9 Jun 2015 16:02:03 +0800 Subject: [PATCH] Update grid.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加行选中与取消事件…… --- sources/js/grid.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sources/js/grid.js b/sources/js/grid.js index 978cacf..c464bda 100644 --- a/sources/js/grid.js +++ b/sources/js/grid.js @@ -154,7 +154,9 @@ curPage: 1, curPageRowsNum: 0, startRow: 0, - endRow: 0 + endRow: 0, + uncheckRowEvent: settings.uncheckRowEvent, + checkRowEvent: settings.checkRowEvent }; if ($('#' + gridId).find('thead').length == 0) { @@ -629,7 +631,7 @@ var data = $.fn.bsgrid.parseData.data(dataType, gridData); var dataLen = data.length; // add rows click event - $.fn.bsgrid.addRowsClickEvent(options); + $.fn.bsgrid.addRowsClickEvent(options,dataType,data,dataLen,totalRows,startRow); $('#' + options.gridId + ' tbody tr').each( function (i) { var trObj = $(this); @@ -690,16 +692,30 @@ options.settings.additionalAfterRenderGrid(parseSuccess, gridData, options); }, - addRowsClickEvent: function (options) { + addRowsClickEvent: function (options,dataType,data,dataLen,totalRows,startRow) { $('#' + options.gridId + ' tbody tr:lt(' + options.curPageRowsNum + ')').click(function () { if ($(this).hasClass('selected')) { + + var i = $('#' + options.gridId + ' tbody tr').index($('#' + options.gridId + ' tbody tr.selected')) + var record = null; + if(i!=null){ + record = $.fn.bsgrid.parseData.getRecord(dataType, data, dataLen != totalRows ? i : startRow + i - 1); + } $(this).removeClass('selected').removeClass('selected_color'); + if(null!=options.uncheckRowEvent){options.uncheckRowEvent(record,i,options);} } else { $.fn.bsgrid.unSelectRow(options); $(this).addClass('selected'); if (options.settings.changeColorIfRowSelected) { $(this).addClass('selected_color'); } + + var i = $('#' + options.gridId + ' tbody tr').index($('#' + options.gridId + ' tbody tr.selected')) + var record = null; + if(i!=null){ + record = $.fn.bsgrid.parseData.getRecord(dataType, data, dataLen != totalRows ? i : startRow + i - 1); + } + if(null!=options.checkRowEvent){options.checkRowEvent(record,i,options);} } }); }, @@ -1071,4 +1087,4 @@ }; -})(jQuery); \ No newline at end of file +})(jQuery);