Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

NEW setForceRedraw() to determine post-drop action

More complex sorting logic can need a serverside refresh
after a drop operation, e.g. if the saved sort column
isn't the primary sorting key.
  • Loading branch information...
commit b1edbc68b7e81e27ea5f231529dee23860ff8d75 1 parent bc3732f
@chillu chillu authored
View
23 code/forms/GridFieldSortableRows.php
@@ -5,7 +5,15 @@
* @package forms
*/
class GridFieldSortableRows implements GridField_HTMLProvider, GridField_ActionProvider, GridField_DataManipulator {
+
protected $sortColumn;
+
+ /**
+ * @var boolean Force a redraw of the field after drop operations.
+ * Can be useful if the sort is more complex, and hence
+ * might be stale after the operation.
+ */
+ protected $forceRedraw = false;
/**
* @param String $sortColumn Column that should be used to update the sort information
@@ -76,8 +84,11 @@ public function getHTMLFragments($gridField) {
Requirements::css('SortableGridField/css/GridFieldSortableRows.css');
Requirements::javascript('SortableGridField/javascript/GridFieldSortableRows.js');
-
- $args = array('Colspan' => count($gridField->getColumns()), 'ID' => $gridField->ID());
+ $args = array(
+ 'Colspan' => count($gridField->getColumns()),
+ 'ID' => $gridField->ID(),
+ 'ForceRedraw' => $this->getForceRedraw(),
+ );
return array('header' => $forTemplate->renderWith('GridFieldSortableRows', $args));
}
@@ -374,5 +385,13 @@ protected function sortToPage(GridField $gridField, $data) {
DB::getConn()->transactionEnd();
}
}
+ public function setForceRedraw($bool) {
+ $this->forceRedraw = $bool;
+ return $this;
+ }
+
+ public function getForceRedraw() {
+ return $this->forceRedraw;
+ }
}
?>
View
8 javascript/GridFieldSortableRows.js
@@ -115,7 +115,13 @@
type: "POST",
url: gridField.data('url'),
dataType: 'html',
- success: callback,
+ success: function(data) {
+ console.debug(gridField.find('.gridfield-sortablerows').data('forceRedraw'));
+ if(gridField.find('.gridfield-sortablerows').data('forceRedraw')) {
+ gridField.reload();
+ }
+ if(callback) callback(data);
+ },
error: function(e) {
alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION'));
}
View
2  templates/Includes/GridFieldSortableRows.ss
@@ -1,6 +1,6 @@
<tr>
<th class="extra sortablerowsheading" colspan="$Colspan">
- <div class="gridfield-sortablerows">
+ <div class="gridfield-sortablerows" data-force-redraw="$ForceRedraw">
<input type="checkbox" id="{$ID}_AllowDragDropCheck" value="1" class="no-change-track"$Checked/> <label for="{$ID}_AllowDragDropCheck"><%t GridFieldSortableRows.ALLOW_DRAG_DROP "_Allow drag and drop re-ordering" %></label>
$SortableToggle
$PagenatorToggle
Please sign in to comment.
Something went wrong with that request. Please try again.