-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Grid): Allow col reordering with column defs
Once initialized, the grid was displaying buggy behavior when swapping column definitions in or out. This change fixes that behavior, and allows for Grid.buildColumns() to reorder columns according to the order of columnDefs by supplying an option parameter with the property `orderByColumnDefs` set to true. This also required changing the call to buildColumns() within the grid's dataWatchFunction so that it uses this option. Fixes #1948
- Loading branch information
Showing
8 changed files
with
215 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!DOCTYPE html> | ||
<html class="no-js" ng-app="test"><!--<![endif]--> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"> | ||
<title></title> | ||
<meta content="width=device-width" name="viewport"> | ||
|
||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" /> | ||
<link href="/dist/release/ui-grid.css" rel="stylesheet"> | ||
|
||
<script src="//code.jquery.com/jquery-2.1.3.min.js"></script> | ||
<script src="/lib/test/angular/1.2.26/angular.js"></script> | ||
<script src="/dist/release/ui-grid.js"></script> | ||
|
||
<style> | ||
body { | ||
padding: 60px; | ||
min-height: 600px; | ||
} | ||
.grid { | ||
width: 500px; | ||
height: 400px; | ||
} | ||
.placeholder { | ||
height: 50%; | ||
width: 50%; | ||
border: 3px solid black; | ||
background: #ccc; | ||
} | ||
</style> | ||
</head> | ||
<body ng-controller="Main"> | ||
<!-- <h1>Test</h1> --> | ||
|
||
<!-- <div class="row main"> --> | ||
<h2>Grid</h2> | ||
<button type="button" ng-click="swap()">Swap Columns</button> | ||
<br> | ||
<br> | ||
<div ui-grid="gridOptions" class="grid"></div> | ||
<!-- <div class="placeholder"> --> | ||
<!-- </div> --> | ||
|
||
<br> | ||
<br> | ||
|
||
<script> | ||
var app = angular.module('test', ['ui.grid']); | ||
app.controller('Main', function($scope, $http) { | ||
var cols1 = [ | ||
{ field:'id', width:50 }, | ||
{ field:'name', width:100 }, | ||
{ field:'age', width:100 } | ||
]; | ||
|
||
var cols2 = [ | ||
{ field:'age', width:100 }, | ||
{ field:'name', width:100 }, | ||
{ field:'id', width:50 } | ||
]; | ||
|
||
// var cols1 = [ | ||
// { name: 'id', field:'id', width:50 }, | ||
// { name: 'name', field:'name', width:100 }, | ||
// { name: 'age', field:'age', width:100 } | ||
// ]; | ||
|
||
// var cols2 = [ | ||
// { name: 'age', field:'age', width:100 }, | ||
// { name: 'name', field:'name', width:100 }, | ||
// { name: 'id', field:'id', width:50 } | ||
// ]; | ||
|
||
$scope.gridOptions = {}; | ||
$scope.gridOptions.columnDefs = cols1; | ||
|
||
$http.get('https://rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json') | ||
.success(function(data) { | ||
$scope.gridOptions.data = data; | ||
}); | ||
|
||
$scope.swap = function () { | ||
($scope.gridOptions.columnDefs === cols1) ? | ||
$scope.gridOptions.columnDefs = cols2 : | ||
$scope.gridOptions.columnDefs = cols1; | ||
}; | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters