删除所有行后如何隐藏智能表?

时间:2014-05-06 08:19:52

标签: angularjs smart-table

我正在使用ng-showsg-hide显示智能表。条件是数据为空,然后隐藏表和数据存在显示表。每次页面都是新加载时它正在工作,但我想通过删除行清空表来应用。 angularjs和smarttable是资源

首次加载时,它会跟随ng-hideng-show以显示表格或其他div。如果没有数据显示,那么我正在隐藏,否则数据存在我显示当我通过删除行动作清空所有行然后删除所有行...然后ng-hide不工作我正在使用angularjs和smarttable

HTML

<div `enter code here`ng-hide="hasdata"->
<smarttable></smarttable>
</div>
<div `enter code here`ng-show="hasdata">
NO data to disply
</div>

控制器

$scope.columncollection;$scope.rowcollection并使用http获取数据并填充rowcollection对象。我们使用自定义指令删除行。首先加载,如果数据长度为零,它工作正常,但行删除,然后它不隐藏。

3 个答案:

答案 0 :(得分:1)

您的表格未被隐藏,因为删除表格内容后,您可能没有将hasdata的值更改为false。

试试这个,

在html中,

<!DOCTYPE html>
<html ng-app="myApp">

  <head>
    <script data-require="angular.js@1.0.7" data-semver="1.0.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="smart-table.js"></script>
    <script src="script.js"></script>
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
  </head>

  <body ng-controller="mainCtrl">
    <h1>{{greetings}} Plunker!</h1>
    <div ng-show="hasdata">
    <smart-table  config="globalConfig" columns="columnsConfig" rows="items"></smart-table>
  </div>

  </body>

</html>

在Js文件中,

var app=angular.module('myApp',['smartTable.table']);

app.controller('mainCtrl',['$scope',function(scope){
  scope.greetings='hello';
  scope.hasdata=true;
  scope.doDelete = function(index) {
  // alert("index "+index);
   scope.items.splice(index,1);

    if(scope.items.length===0){
    //alert("scope.items.length "+scope.items.length);
    scope.hasdata=false;
  }

  }




scope.items=[
    {name:'mahesh',lastName:'kumar'},
    {name:'sachin',lastName:'ramesh'},
    {name:'varun',lastName:'gupta'},
    {name:'vijay',lastName:'kumar'},
    {name:'prem',lastName:'raj'},
    {name:'gandhi',lastName:'gandhi'},
    {name:'sathish',lastName:'kumar'},
    {name:'ram',lastName:'prasad'},
    {name:'siva',lastName:'guru'},
    {name:'dilli',lastName:'ganesh'}
    ];

  scope.globalConfig={
    isPaginationEnabled:false,
    selectionMode:'single'
  };

  scope.columnsConfig=[
    {label:'name',map:'name'},
    {label:'last Name',map:'lastName'},
    {label:'actions',cellTemplateUrl:'delete.html'}
    ];




}])

在delete.html中,

<button ng-click="$parent.$parent.$parent.$parent.doDelete(displayedCollection.indexOf(dataRow))"
    class="btn btn-xs btn-primary">
        Delete
</button>

查看plunker

中的工作演示

希望这能解决你的问题:)

答案 1 :(得分:0)

如果在删除所有表行后确定隐藏条件为真(数据为空),可以通过在每行删除后记录(console.log)条件来检查,那么您可能只需要执行$scope.apply()$scope.digest()以确保您的视图已更新。

如果您将代码添加到问题中,那么更容易为您提供更完整的答案。

答案 2 :(得分:0)

您可能需要在$apply调用中包含删除行的代码。

$scope.$apply(function() {
    //delete rows here
})
相关问题