我想要一个函数,它接受一个数据表并返回一个List(对象不是DataRow)例如.:
我知道我可以这样做(但这需要知道列名):
// Datatable dt = Filled from a Database query & has 3 columns Code,Description & ShortCode
List<object> rtn = new List<object>();
var x = from vals in dt.Select()
select new
{
Code = vals["Code"],
Description = vals["Description"],
ShortCode = vals["ShortCode"],
};
rtn.AddRange(x)
return rtn;
Run Code Online (Sandbox Code Playgroud)
我想要的是一个通用版本,以便我可以传入任何数据表,它将根据数据表中的列名生成.
我正在使用bootstrap数据表进行分页.我还为每一行添加了click事件.但是click事件只在第一页中触发.排序或分页后它不起作用.这是我的PHP代码来显示数据
<table id='tblCustomers' class='table table-bordered table-striped'>
<thead>
<tr>
<th>Customer id</th>
<th>Company</th>
<th>First name</th>
<th>Last name</th>
<th>Email</th>
<th>Last login</th>
<th>No Of logins </th>
</tr>
</thead>
<tbody>";
foreach ($this->result as $row) {
echo "<tr>
<td>{$row['customerid']} </td>
<td>{$row['company']} </td>
<td>{$row['firstname']} </td>
<td>{$row['lastname']} </td>
<td>{$row['email']} </td>
<td>{$row['lastlogin']} </td>
<td>{$row['count']}</td>
</tr>";
}
echo "</tbody></table>";
Run Code Online (Sandbox Code Playgroud)
和jquery代码是
$(function () {
$("#tblCustomers").dataTable();
$("#tblCustomers tr").click(function(){
alert($(this).find('td:first').text());
});
});
Run Code Online (Sandbox Code Playgroud) 我使用DataTables与Jquery,我有一个JSON我想通过获取对象数据源Ajax在表中和显示.
JSON数据从/live/log网址返回,格式如下:
{
"Logs": [
{
"date": "2015-04-22T14:00:39.086Z",
"eventType": "event1",
"str": "Application startup"
},
{
"date": "2015-04-22T14:01:27.839Z",
"eventType": "event2",
"str": "test Logged in"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我的表格HTML:
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Date</th>
<th>Event</th>
<th>Description</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Date</th>
<th>Event</th>
<th>Description</th>
</tr>
</tfoot>
</table>
Run Code Online (Sandbox Code Playgroud)
最后JS用于获取和填充数据表:
$(document).ready(function() {
$('#example').dataTable( {
"ajax": "/live/log",
"columns": [
{"data": "date"},
{"data": "eventType"},
{"data": "str"}
]
});
});
Run Code Online (Sandbox Code Playgroud)
我可以通过调试器看到JSON数据正在被正确获取.
我似乎在 …
有没有办法pageLength在jQuery的"window.resize"事件中更改运行时dataTable 的设置?
这些是我正在使用的dataTable设置
$('#dataTable').DataTable({
paging: true,
pageLength: 35,
searching: true,
lengthChange: false,
info: false,
scrollCollapse: true,
scrollY: "calc(74vh)"
});
Run Code Online (Sandbox Code Playgroud)
pageLength每当窗口调整大小时,我希望更改.
我正在尝试这个
$(window).resize(function () {
if ($(this).height() >= "1080"){
// change the dataTable pageLength in here
$('#dataTable').DataTable({ pageLength: 50 });
} else {
// default pageLength
$('#dataTable').DataTable({ pageLength: 35 });
}
});
Run Code Online (Sandbox Code Playgroud) 我的.xhtml数据库看起来像这样:
<p:dataTable var="category" value="#{beanView.categories}" paginator="true" rows="5"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10" id="categoryDT" styleClass="categoryClass"
editable="true" lazy="false" rowKey="#{category.id}">
<!-- columns -->
<f:facet name="footer">
<p:commandButton id="btnNewCat"
oncomplete="jQuery('.categoryClass').find('span.ui-icon-pencil').last().click();"
actionListener="#{beanView.onNewCategory}"
update="categoryDT" icon="ui-icon-plus" title="New Category" value="New Category" ></p:commandButton>
</f:facet></p:dataTable>
Run Code Online (Sandbox Code Playgroud)
而我的bean beanView:
public void onNewCategory(final ActionEvent actionEvent) {
try {
int rowCount = dataTable.getRowCount();
int rowsPerPage = dataTable.getRows();
int lastPage = rowCount / rowsPerPage;
int rowFirst = (lastPage * rowsPerPage);
if (rowCount >= rowsPerPage) {
dataTable.setFirst(rowFirst);
dataTable.setPageLinks(lastPage + 1);
dataTable.setRowIndex(rowCount - 1);
} else …Run Code Online (Sandbox Code Playgroud) 我试图在Web上使用数据表,但是在我将所有内容添加到Web后,它并没有显示我看到的模板那样的内容。这是模板
这就是我得到的

我的意思是我看不到加号按钮,所以我看不到产品的详细信息。此按钮仅在我使浏览器变小时显示,但是即使浏览器像模板中的那样大,我也需要

你有什么想法,请帮忙?这是我遵循的模板:https : //datatables.net/extensions/response/examples/display-types/foundation-modal.html 这是我的脚本:
$(document).ready(function() {
$('#example').DataTable( {
responsive: {
details: {
display: $.fn.dataTable.Responsive.display.modal( {
header: function ( row ) {
var data = row.data();
return 'Details for '+data[0]+' '+data[1];
}
} ),
renderer: function ( api, rowIdx, columns ) {
var data = $.map( columns, function ( col, i ) {
return '<tr>'+
'<td>'+col.title+':'+'</td> '+
'<td>'+col.data+'</td>'+
'</tr>';
} ).join('');
return $('<table width="100%"/>').append( data );
}
}
}
} );
Run Code Online (Sandbox Code Playgroud)
});
我今天一直在用LINQ和DataTable进行实验.
var query = from row1 in table1.AsEnumerable()
from row2 in table2.AsEnumerable()
where
(row1.Field<string>("a") == row2.Field<string>("b"))
select new Foo
{
Property1 = row1.Field<string>("Hey")
Property2 = row2.Field<string>("Ho")
};
Run Code Online (Sandbox Code Playgroud)
并得出奇怪的结论,无论我做什么select new Foo或select new Foo()查询工作完全相同.我真的希望与代表等进一步深入了解linq机制,以便清楚地理解这一点 - 但就目前而言,对于一个简单的人来说 - 是否存在差异,如果是这样,那会是什么?
编辑
问题在SOF上已有一些类似的答案,但"对象初始化程序"并不是最重要的.它也非常具体地针对LINQ,其中90%的网络提示操作匿名类型(不知道为什么,我发现使用具体类型的一些好处,特别是Intellisense).如果任何材料确实在LINQ中指定具体类型实现示例,我只能找到new Foo没有括号.使用LINQ构建尤其适合初学者,可能很难找到那里初始化的内容(对象,委托,谓词等 - 至少对我来说是这样)所以希望至少有些人会发现问题和响应很有用.
我正在使用数据表v1.10.11和Jquery v 2.2.0
我有一张桌子,上面有两个输入搜索过滤器;
<input type="text" id="myInputTextField1" class="form-control"> <!--search one-->
<input type="text" id="myInputTextField2" class="form-control"> <!--search two-->
Run Code Online (Sandbox Code Playgroud)
我的数据表JS;
$(document).ready(function() {
$('#example').dataTable({});
});
$('#myInputTextField1').keyup(function(){
table.search($(this).val()).draw() ;
})
$('#myInputTextField2').keyup(function(){
table.search($(this).val()).draw() ;
})
Run Code Online (Sandbox Code Playgroud)
搜索工作正常,没有问题。
我如何合并一个简单的按钮,当单击该按钮时,它将清除两个输入字段并将表重置为默认状态?例如;
<button type="button" id="test">Clear Filters</button>
<table id="example">
<thead>
<tr>
<th>COLUMN 1</th>
<th>COLUMN 2</th>
<th>COLUMN 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>ROW 1</td>
<td>ROW 1</td>
<td>ROW 1</td>
</tr>
<tr>
<td>ROW 2</td>
<td>ROW 2</td>
<td>ROW 2</td>
</tr>
<tr>
<td>ROW 3</td>
<td>ROW 3</td>
<td>ROW 3</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏。
我有一个列TRUE或FALSE值
data("mtcars")
mtcars$Favorite <- "FALSE"
Run Code Online (Sandbox Code Playgroud)
我有兴趣将此列(收藏夹)显示为闪亮的复选框.
runApp(list(
ui = basicPage(
h2('The mtcars data'),
dataTableOutput('mytable')
),
server = function(input, output) {
output$mytable = renderDataTable({
mtcars
})
}
))
Run Code Online (Sandbox Code Playgroud)
资料来源:http://shiny.rstudio.com/articles/datatables.html
不知道如何使它工作,任何帮助非常感谢.
我正在尝试使用TextChanged()事件在文本框中填充SQL Server中的自动填充文本。 [WindowsForm, C#]
我有部分课程表格
TextChanged事件:
private void textBoxFilterCName_TextChanged(object sender, EventArgs e)
{
DataTable dt = FillCustomerName(textBoxFilterCName.Text);
List<string> listNames = CustomerName.ConvertDataTableToList(dt);
textBoxFilterCName.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
AutoCompleteStringCollection dataName = new AutoCompleteStringCollection();
dataName.AddRange(listNames.ToArray());
textBoxFilterCName.AutoCompleteCustomSource = dataName;
textBoxFilterCName.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
Run Code Online (Sandbox Code Playgroud)
调用此方法时遇到此错误CustomerName.ConvertDataTableToList()。
无法从用法中推断方法'CustomerName.ConvertDataTableToList(DataTable)'的类型参数。尝试显式指定类型参数。
FillCustomerName()方法
public DataTable FillCustomerName(string cName)
{
DataTable dtName = new DataTable();
List<string> listName = new List<string>();
try
{
dbconnection.Open();
string query = "SELECT [Name] FROM Customers WHERE Is_Active=1 AND Name like @CName + '%'";
using (SqlCommand cmd = new …Run Code Online (Sandbox Code Playgroud) datatable ×10
jquery ×6
javascript ×4
c# ×3
linq ×2
ajax ×1
datatables ×1
jsf ×1
jsf-2 ×1
json ×1
list ×1
primefaces ×1
r ×1
shiny ×1
sql-server ×1