Ich verwende das dataTables jQuery-Plug-in für eine Tabelle, aber ich möchte vor dem Suchfeld ein Dropdown-Feld Filterspalte hinzufügen. Ich sehe die Dokumentation zum Hinzufügen von Dropdown-Boxen zu einzelnen Spalten, aber ich möchte nur eine Dropdown-Box hinzufügen, die alle Spaltennamen enthält. Ich bin neu dazu und würde jede Hilfe sehr schätzen. Ich habe meinen Code unten hinzugefügt.Jquery-Datentabelle: Filter/Suche basierend auf Auswahlfeld außerhalb der Tabelle
HTML:
<select id='mySelector'>
<option value="">Please Select</option>
<option value='Name'>Name</option>
<option value='Highlights'>Highlights</option>
<option value='Area'>Area</option>
</select>
<table class="table table-striped" id="myTable" cellspacing="0">
@{int rowNo = 0;}
<thead>
<tr>
<th>
Item
</th>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Highlights)
</th>
<th>
@Html.DisplayNameFor(model => model.Area)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Select((x, i) => new { Data = x, Index = i + 1 }))
{
rowNo++;
<tr>
<td>
@rowNo.ToString("000")
</td>
<td>
@Html.DisplayFor(modelItem => item.Data.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Data.Highlights)
</td>
<td>
@Html.DisplayFor(modelItem => item.Data.Area)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Data.id}) |
@Html.ActionLink("Details", "Details", new { id = item.Data.id}) |
@Html.ActionLink("Delete", "Delete", new { id = item.Data.id})
</td>
</tr>
}
</tbody>
</table>
JS:
$('#myTable').DataTable();
https://stackoverflow.com/questions/34128094/adding-more-drop-down-or-html-elements-to-datatable-in-jquery – davidkonrad
Mein Ziel ist es, eine Dropdown-Liste von Spaltennamen zu haben (keine Werte) und wenn ich den Suchwert eintippe, möchte ich, dass die Tabelle Datensätze anzeigt, die diesen Wert nur in der ausgewählten Spalte haben (im Gegensatz zu allen Spalten). – user7221204