Javascript 如何在angular ui网格中禁用客户端排序?
我有两个问题Javascript 如何在angular ui网格中禁用客户端排序?,javascript,angularjs,angular-ui,angular-ui-grid,ui-grid,Javascript,Angularjs,Angular Ui,Angular Ui Grid,Ui Grid,我有两个问题 我正试图在ui网格中禁用客户端排序,我该怎么做 我需要将另一个数据集设置为ui网格并刷新数据集,而不是客户端排序 scope.gridOptions.data=res scope.gridApi.core.refresh() 我尝试将新数据分配到ui网格并刷新ui网格的第一个链接。这不管用吗?我该怎么做 谢谢要禁用ui网格的客户端排序,您需要在网格定义上设置enableSorting:false 重置 var-app=angular.module('app',['ngAnima
scope.gridOptions.data=res
scope.gridApi.core.refresh()代码>
谢谢要禁用ui网格的客户端排序,您需要在网格定义上设置
enableSorting:false
重置
var-app=angular.module('app',['ngAnimate','ngTouch','ui.grid']);
app.controller('MainCtrl',['$scope','$http','uiGridConstants',函数($scope,$http,uiGridConstants){
$scope.gridOptions1={
启用排序:false,
columnDefs:[
{
字段:“名称”
},
{
字段:“性别”
},
{
字段:“公司”
}
],
onRegisterApi:函数(gridApi){
$scope.grid1Api=gridApi;
}
};
$scope.toggleGender=函数(){
如果($scope.gridOptions1.data[64].gender=='male'){
$scope.gridOptions1.data[64]。性别='female';
}否则{
$scope.gridOptions1.data[64]。性别='male';
};
$scope.grid1Api.core.notifyDataChange(uiGridConstants.dataChange.EDIT);
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.成功(功能(数据){
$scope.gridOptions1.data=数据;
});
$scope.resetGrid=函数(){
$scope.gridOptions1.data=[
{
‘公司’:‘公司1’,
‘性别’:‘性别1’,
“名称”:“名称1”
},
{
‘公司’:‘公司2’,
‘性别’:‘性别2’,
“名称”:“名称2”
}
];
}
}]);
要禁用ui网格的客户端排序,需要在网格定义上设置启用排序:false
重置
var-app=angular.module('app',['ngAnimate','ngTouch','ui.grid']);
app.controller('MainCtrl',['$scope','$http','uiGridConstants',函数($scope,$http,uiGridConstants){
$scope.gridOptions1={
启用排序:false,
columnDefs:[
{
字段:“名称”
},
{
字段:“性别”
},
{
字段:“公司”
}
],
onRegisterApi:函数(gridApi){
$scope.grid1Api=gridApi;
}
};
$scope.toggleGender=函数(){
如果($scope.gridOptions1.data[64].gender=='male'){
$scope.gridOptions1.data[64]。性别='female';
}否则{
$scope.gridOptions1.data[64]。性别='male';
};
$scope.grid1Api.core.notifyDataChange(uiGridConstants.dataChange.EDIT);
};
$http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')
.成功(功能(数据){
$scope.gridOptions1.data=数据;
});
$scope.resetGrid=函数(){
$scope.gridOptions1.data=[
{
‘公司’:‘公司1’,
‘性别’:‘性别1’,
“名称”:“名称1”
},
{
‘公司’:‘公司2’,
‘性别’:‘性别2’,
“名称”:“名称2”
}
];
}
}]);
只需将属性enableSorting=false放入,即可解决排序问题
enableSorting:false
只需将属性enableSorting=false与解决排序问题
enableSorting:false
对于第一个问题,要禁用ui网格的客户端排序,您需要在
gridOptions
中使用false设置此标志,如下所示:
scope.gridOptions.enableSorting: false;
对于第二个问题,要通过重新设置网格数据来更改视图,请尝试在之后添加此行:
scope.$apply
对于第一个问题,要禁用ui网格的客户端排序,您需要在
gridOptions
中使用false设置此标志,如下所示:
scope.gridOptions.enableSorting: false;
对于第二个问题,要通过重新设置网格数据来更改视图,请尝试在之后添加此行:
scope.$apply
您使用的网格是哪个?你能分享这个URL吗?这是我正在使用的ui网格,也就是你使用过的网格?您可以共享URL吗?这是我正在使用的ui网格谢谢@Nitheesh,您知道如何刷新数据集吗?为了刷新数据集,您需要重置网格的数据源,即需要将新数据源设置为$scope.gridOptions1.dataI已根据您的要求更新了代码段谢谢@Nitheesh,您知道如何刷新数据集吗?为了刷新数据集,您需要重置网格的数据源,即需要将新数据源设置为$scope.gridOptions1.dataI have update