我有一个根据另一个日期列计算的列,以年/月/日格式显示.我还希望将此列排序为日期列,但由于它是一个字符串,因此排序方式不同.
这是我的数据库配置代码.
"columnDefs": [{ // set default column settings
'orderable': false,
'targets': [1, 9]
}, {
"searchable": false,
"targets": [1, 9]
}],
"order": [
[5, "asc"]
] // set first column as a default sort by ascRun Code Online (Sandbox Code Playgroud)
有什么方法可以将第6列"At Work"的排序附加到第5列?
谢谢您的帮助..
我正在使用启用了响应选项的jquery数据表.当表处于响应模式时,我无法返回行数据:
我的桌子:
$('#productsTable').DataTable({
responsive: true
});
Run Code Online (Sandbox Code Playgroud)
该表格包含产品代码,品牌,类别,价格和"添加到购物车"按钮的列.该按钮应该检索行数据.但是,当表处于响应模式(也就是它缩小并且某些列已经折叠)并且我单击我的按钮时,它不会返回任何数据.
我的html表:
<table id="productsTable" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Product Code</th>
<th>Brand</th>
<th>Category</th>
<th>Price ($)</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each context}}
<tr>
<td class="product_code">{{product_code}}</td>
<td class="brand">{{brand}}</td>
<td class="category">{{category}}</td>
<td class="price">{{invoice_price}}</td>
<td><button type="button" class="btn btn-primary">Add to Cart</button></td>
</tr>
{{/each}}
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我添加到购物车事件:
$(".btn-primary").click(function(e) {
var price = $(this).parent().parent().children('td.price').text();
var context = {
product_code: $(this).parent().parent().children('td.product_code').text(),
brand: $(this).parent().parent().children('td.brand').text(),
category: $(this).parent().parent().children('td.category').text(),
price: $(this).parent().parent().children('td.price').text(),
};
console.log(context) //console.logs context
});
Run Code Online (Sandbox Code Playgroud)
折叠表的图像:
有人可以帮忙吗?
提前致谢!
我的viewModel是:
public class MainWindowViewModel
{
public MainWindowViewModel()
{
PopulateDataTable();
}
private DataTable employeeDataTable;
public DataTable EmployeeDataTable
{
get { return employeeDataTable; }
set
{
employeeDataTable = value;
OnPropertyChanged("EmployeeDataTable");
}
}
private void PopulateDataTable()
{
var _ds = new DataSet("Test");
employeeDataTable = new DataTable();
employeeDataTable = _ds.Tables.Add("DT");
for (int i = 0; i < 10; i++)
{
employeeDataTable.Columns.Add("Column " + i.ToString());
}
for (int i = 0; i < 15; i++)
{
var theRow = employeeDataTable.NewRow();
for (int j = 0; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用json格式的静态数据创建一个数据表,而不通过ajax请求命中服务器来获取json源数据.试图找到一种方法,但没有运气.我可以用静态json数据变量来做,如下所示,
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery DataTable</title>
<link rel="stylesheet" href="jquery-ui.css">
<link rel="stylesheet" type="text/css" href="demo_table_jui.css" />
<link rel="stylesheet" type="text/css" href="jquery-ui-1.7.2.custom.css" />
<script src="jquery-1.10.2.js"></script>
<script src="jquery-ui.js"></script>
<script type="text/javascript" src="complete.min.js"></script>
<script type="text/javascript" src="jquery.dataTables.min.js"></script>
<script>
$(function() {
var jsonData = [{"userID":"1","userName":"name1"},{"userID":"2","userName":"name2"},{"userID":"3","userName":"name3"}];
$('#example').dataTable({
data: jsonData,
columns: [
{ data: 'userID' },
{ data: 'userName' }
]
});
});
</script>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" align="center">
<thead>
<tr>
<th>UserID</th>
<th>userName</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
请举例说明这样做的方法.提前致谢.
我有一个数据表(使用jQuery创建),其第一列包含复选框,最后一列包含文本框。由于textbox和checkbox是动态创建的,因此它们具有相同的ID和名称,如下所示:
$('#statement-table').dataTable({
"data": json,
"dom": 't',
"columns": [
{"data":""},
{"data": "statementCode"},
{"data": "dueDate"},
{"data": "statementBalance"},
{"data": ""}
],
"columnDefs": [
{className: "pad-md-left-p-10 pad-top-bottom-p-10 white-active-bg mouse-link", "targets": [0,1,2,3,4]},
{
'targets': 0,
'orderable': false,
'render': function(data, type, full, meta) {
return '<input type="checkbox" name="payment-checkbox" id="select-checkbox"/>';
}
},
{
'targets': 4,
'render': function (data, type, full, meta){
return
'<input type="number" id="payement-textbox" name="text[]" class="payment" value=""/>';
}
}
],
"aaSorting": [[2, 'desc']],
}); //End of datatable function
Run Code Online (Sandbox Code Playgroud)
我的要求是在未选中其对应复选框时清除文本框值。我写了下面的jQuery代码,但没有清除文本框:
$("input[name=payment-checkbox]").click(function () {
$("table tr td input[type='checkbox']").each(function …Run Code Online (Sandbox Code Playgroud) 我想使用JSF(Primefaces)将数据从Excel复制并粘贴到Datatable.请建议我实现复制和粘贴的可能性.
我需要在C#上使用公共列合并/连接数据表.
我知道很多例子以及有关同一主题的问题.我没有找到任何回答我的问题.
以下是我正在使用的代码.
该代码仅允许基于on datatable数据的一个公共列.我需要一个公共列,但需要考虑任何其他"帐户#"可以在另一个数据表中使用并将其添加到公共列中.
此外,代码仅允许合并2个数据表.我需要合并31个数据表,以便为每个月的每一天合并1个数据表.
我有一个月的每一天的数据表,dt_docDAY01,dt_docDAY02,dt_docDAY03等.
每个数据表包含一个帐号"帐号#"和一个存储在一列中的余额,参考当天"DAY01","DAY02"等.
你能告诉我如何更改代码,以便我将包括所有表中的所有帐户.
另外,我将如何合并此代码中的所有数据表,所以我不必运行相同的代码31次.
'string id ="帐号#";
var tableJoinedDAY02 = dt_docDAY01_GROUPED.Clone(); // create columns from table1
// add columns from table2 except id
foreach (DataColumn column in dt_docDAY02_GROUPED.Columns)
{
if (column.ColumnName != id)
tableJoinedDAY02.Columns.Add(column.ColumnName, column.DataType);
}
tableJoinedDAY02.BeginLoadData();
foreach (DataRow row1 in dt_docDAY01_GROUPED.Rows)
{
foreach (DataRow row2 in dt_docDAY02_GROUPED.Rows)
{
if (row1.Field<string>(id) == row2.Field<string>(id))
{
var list = row1.ItemArray.ToList(); // items from table1
// add items from table2 except id
foreach (DataColumn column in dt_docDAY02_GROUPED.Columns) …Run Code Online (Sandbox Code Playgroud) 我在这里回顾了答案:
但它们对我的特定用例没有帮助.我正在从SQL数据适配器检索DataTable,并希望将DataTable转换为List(这很容易),然后将List序列化为JSON(使用JSON.net,这很容易).
问题是我似乎必须使用List.好的,很好 - 所以我有这个代码:
DataTable result = GoMagicallyGatherSomeData();
List<DataRow> ret = new List<DataRow>();
if (result != null && result.Rows.Count > 0)
{
foreach (DataRow curr in result.Rows)
{
ret.Add(curr);
}
}
Run Code Online (Sandbox Code Playgroud)
要么
DataTable result = GoMagicallyGatherSomeData();
List<DataRow> ret = result.AsEnumerable().ToList();
Run Code Online (Sandbox Code Playgroud)
当我去序列化List时,它......不是我所期望的.
我想回来的是:
[
{
"TestId":1,
"AccountId":1,
"SomeString":"This is an updated test",
"SomeTimestamp":"2016-01-01T00:00:00Z",
"SomeDecimal":5.55
},
{
"TestId":3,
"AccountId":1,
"SomeString":"This is a third test",
"SomeTimestamp":"2016-01-01T00:00:00Z",
"SomeDecimal":5.55
},
{ ... removed for brevity ... }
]
Run Code Online (Sandbox Code Playgroud)
而我实际得到的是: …
我在页面加载时有一个默认的数据表,当我更改页面上的下拉选项时,我想使用所选的下拉值循环遍历现有的数据表.
由于我的下拉是多选下拉,因此很有可能发送多个值来循环数据表.
对于这个scenariao,我在默认数据表上使用了linq qyery.像这样:
var zones = from myRow in ds.Tables[1].AsEnumerable()
where myRow.Field<string>("BusinessUnitId").Contains(BUIds)
select myRow;
dt = zones.CopyToDataTable<DataRow>();
Run Code Online (Sandbox Code Playgroud)
它适用于下拉列表的单个值.但是,当传递多个ID时,查询不会返回行和行.
注意:BUIds是一个字符串变量.(例如:"1,2")
有人可以告诉我我的代码中缺少什么吗?
我有一个简单的数据表,有四列和一些数据行:
DataTable results = new DataTable();
results.Columns.Add("Wellbore", typeof(string));
results.Columns.Add("Date", typeof(DateTime));
results.Columns.Add("WB", typeof(string));
results.Columns.Add("factor", typeof(double));
Run Code Online (Sandbox Code Playgroud)
当"date = 1/1/2017"时,我使用Linq查询获取"数据行列表":
var AllRowsAtPlanningDate = results.AsEnumerable()
.Where(x => ((x.Field<DateTime>("Date") == PlanningDate))).ToList();
Run Code Online (Sandbox Code Playgroud)
我想在" "列中获得"不同"值.我只想要而不是再次.wellboreAllRowsAtPlanningDateList<string>list<datarows>
怎么做?我一直在检查一些例子,但无济于事.