From eec20a7a518f6290afe321b15c0fb47e7dfc8b60 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Fri, 5 Apr 2013 18:28:36 +0200 Subject: [PATCH] feature #1825: Standing selection on datatable refresh --- src/sunstone/public/js/layout.js | 6 ++-- src/sunstone/public/js/sunstone-util.js | 42 ++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/sunstone/public/js/layout.js b/src/sunstone/public/js/layout.js index 3fc6a89edf..7ba774c4d4 100644 --- a/src/sunstone/public/js/layout.js +++ b/src/sunstone/public/js/layout.js @@ -36,9 +36,9 @@ function showTab(tabname,highlight_tab){ //we no longer expect #tab_id here, but simply tab_id //So safety check - remove # from #tab_id if present to ensure compatibility - $('tbody input.check_item:checked').click(); - $('td').removeClass('markrowchecked markrowselected'); - last_select_row = null; + //$('tbody input.check_item:checked').click(); + //$('td').removeClass('markrowchecked markrowselected'); + last_selected_row = null; if (tabname.indexOf('#') == 0) tabname = tabname.substring(1); diff --git a/src/sunstone/public/js/sunstone-util.js b/src/sunstone/public/js/sunstone-util.js index dcfc2dd072..8ffa3458d8 100644 --- a/src/sunstone/public/js/sunstone-util.js +++ b/src/sunstone/public/js/sunstone-util.js @@ -191,9 +191,14 @@ function tableCheckboxesListener(dataTable){ var datatable = $(this).parents('table'); if($(this).is(":checked")) + { $(this).parents('tr').children().each(function(){$(this).addClass('markrowchecked');}); + } else - $(this).parents('tr').children().each(function(){$(this).removeClass('markrowchecked');}); + { + $(this).parents('tr').children().removeClass('markrowchecked'); + $(this).parents('tr').children().removeClass('markrowselected'); + } recountCheckboxes(datatable); }); @@ -202,11 +207,46 @@ function tableCheckboxesListener(dataTable){ // Updates a data_table, with a 2D array containing the new values // Does a partial redraw, so the filter and pagination are kept function updateView(item_list,dataTable){ + var selected_row_id = $($('td.markrowselected',dataTable.fnGetNodes())[1]).html(); + var checked_row_ids = new Array(); + + $.each($(dataTable.fnGetNodes()), function(){ + if($('td.markrowchecked',this).length!=0) + { + checked_row_ids.push($($('td',$(this))[1]).html()); + } + }); + if (dataTable) { dataTable.fnClearTable(); dataTable.fnAddData(item_list); dataTable.fnDraw(false); }; + + if(selected_row_id) + { + $.each($(dataTable.fnGetNodes()),function(){ + if($($('td',this)[1]).html()==selected_row_id) + { + $('td',this)[2].click(); + } + }); + } + + if(checked_row_ids.length!=0) + { + $.each($(dataTable.fnGetNodes()),function(){ + var current_id = $($('td',this)[1]).html(); + if (current_id) + { + if(jQuery.inArray(current_id, checked_row_ids)!=-1) + { + $('input.check_item',this).first().click(); + $('td',this).addClass('markrowchecked'); + } + } + }); + } } //replaces an element with id 'tag' in a dataTable with a new one