我正在使用Infragisitics 17.1 UltraGrid。
网格有2列。
我想要第二列的格式化字符串,如下所示。
' 20170102123456' => ' 2017-01-02 12:34:56"
第二列的数据类型是' string'不是' date'。
此网格将包含大量数据,因此任何转换都让我担心。
但任何欢迎都是受欢迎的。
DataSoure就像下面一样。
private void SetTestData()
{
DataTable dtDataSource = new DataTable("table1");
dtDataSource.Columns.Add("OrderDate", typeof(DateTime));
dtDataSource.Columns.Add("RequiredDate", typeof(string));
ultraGrid1.DataSource = dtDataSource;
DataRow rowNew = dtDataSource.NewRow();
rowNew["OrderDate"] = DateTime.Now;
rowNew["RequiredDate"] = "20170101123456";
dtDataSource.Rows.Add(rowNew);
}
我初始化网格就像下面一样,
private void UltraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
// Fit columns
e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn;
// Set date formats
e.Layout.Bands[0].Columns["OrderDate"].Format = "yyyy-MM-dd HH:mm:ss";
e.Layout.Bands[0].Columns["RequiredDate"].Format = "yyyy-MM-dd HH:mm:ss";
}
第一列工作正常,但第二列没有。
如何在下面显示第二列?
' 20170102123456' => ' 2017-01-02 12:34:56"
答案 0 :(得分:0)
UltraGrid无法单独进行此对话。在这种特定情况下你可以做的是实现你自己的自定义IEditorDataFilter。为此,请更改您的InitializeLayuot:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Cart</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Language" content="en-us">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/1061ab0407.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
</head>
<body>
<div id="wrap">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav ml-auto">
<li class="nav-item active dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
</div>
</nav>
<div class="main-content">
<div class="container-fluid">
<!-- header -->
<div class="row">
<div class="col-md-8">
<div class="card bg-light mb-3">
<table class="table">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>blah1</td>
<td>$12.10</td>
<td>
<form action="/new/cart/100" method="post" class="form-inline">
<input type="text" name="quantity" value="1" size="6" class="form-control input-sm">
<input type="hidden" name="item" value="2">
<input type="submit" value="Update" class="btn btn-primary btn-sm"> <input type="submit" name="remove" value="Remove" class="btn btn-danger btn-sm">
</form>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-4">
<div class="card bg-light mb-3">
<h4 class="card-title">Cart summary</h4>
<ul class="list-group list-group-flush">
<li class="list-group-item">Total</li>
<li class="list-group-item">$17.60</li>
<li class="list-group-item">Coupon
<form action="/new/cart/100" method="post" class="form-inline">
<input type="text" name="coupon" value="" size="10" class="form-control input-sm">
<input type="submit" value="Update" class="btn btn-primary btn-sm">
</form></li>
</ul>
<a href="/coursecode1/slim/public/order" class="btn btn-default">Checkout</a>
<!-- /div -->
</div>
</div>
<!-- footer -->
</div>
</div>
</div>
<div id="footer">
<div class="container">
<center>All Rights Reserved.</center>
</div>
</div>
</body>
</html>
然后像这样创建自定义DataFilter:
private void UltraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
{
// Fit columns
e.Layout.AutoFitStyle = AutoFitStyle.ExtendLastColumn;
// Set date formats
e.Layout.Bands[0].Columns["OrderDate"].Format = "yyyy-MM-dd HH:mm:ss";
// You do not need this as the column data type is string
//e.Layout.Bands[0].Columns["RequiredDate"].Format = "yyyy-MM-dd HH:mm:ss";
// Set the column's editor DataFilter instead
e.Layout.Bands[0].Columns["RequiredDate"].Editor.DataFilter = new DF();
}