如何在ng-table选择过滤器上放置占位符文本?

时间:2016-08-02 16:11:24

标签: javascript html angularjs ngtable

代码示例: https://plnkr.co/edit/hdYjHtEx1Dto1q6UVCS9

$scope.idFilter = {
    id: {
      id: "number",
      placeholder: "Filter by id", // Working
    }
  };

  $scope.nameFilter = {
    id: {
      id: "text",
      placeholder: "Filter by name", // Working
    }
  };

  $scope.statusFilter = {
    status: {
      id: "select",
      placeholder: "Filter by status", // Not working
    }
  };

在ngTable中的数字或文本过滤器上添加占位符很容易。但是我无法找到选择过滤器的解决方案。我知道选择'元素本身并不是微不足道的,但它是可以实现的。

你能在ngTable中找到解决方案吗?
如果没有,你能推荐另一个具有此功能的表组件吗?

2 个答案:

答案 0 :(得分:2)

您可以使用val:''在您的选择中添加额外选项以模拟占位符:

{
  id: '',
  title: 'Filter by Status'
}

添加默认过滤器以引用"按状态过滤"

$scope.myTableParams = new NgTableParams({filter: { status: ""}}, {
    counts: [],
    dataset: users
});

结果: https://plnkr.co/edit/luaas1dExIuCYMa4WtN3?p=preview

更新:
添加此CSS以便将占位符外观与其他选项区分开来:

/* Set the select filter placeholder item look */
table.ng-table select.filter-select.ng-empty {
  color: gray;
}

/* Prevent select filter placeholder look to cascade to its options */
table.ng-table select.filter-select > option {
  color: #767676;
}

答案 1 :(得分:0)

完成@CMedina答案:

对于多种选择过滤器,您可以创建另一个“ statusFilter”对象:

plot(irf(VAR_reduced, n.ahead = 40))

,然后将其添加到之前创建的ngTableParams过滤器中:

library(quantmod)
library(urca)
library(vars)
library(tseries)
getSymbols('CPILFESL',src='FRED')
getSymbols('INDPRO',src='FRED')
getSymbols('WALCL',src='FRED')
CPI <- ts(CPILFESL, frequency = 12, start = c(1957,1))
output <- ts(INDPRO, frequency = 12, start = c(1919,1))
assets <- as.xts(WALCL)
assets <- to.monthly(assets, indexAt='yearmon', drop.time = TRUE)
assets <- ts(assets[,4], frequency = 12, start = c(2002,12))
assets <- window(assets, start = c(2008,9), end = c(2020,1))
CPI <- window(CPI, start = c(2008,9), end = c(2020,1))
output <- window(output, start = c(2008,9), end = c(2020,1))
loutput <- log(output)
lCPI <- log(CPI)
data_0 <- cbind(loutput, lCPI, assets)
plot(data_0)
VAR_data_1 <- ts.intersect(diff(loutput), diff(lCPI), diff(assets, differences = 2))
VAR_reduced <- VAR(VAR_data_1, p = 1, type = "both")
summary(VAR_reduced)

别忘了更新您的DOM。