I have a gridview and i add a search textbox in every coloumn using jquery. I try to search in the textbox it works nice. But here i have two problem:
-
When i search to the gridline and select the row, it retu me the row before the row i selected.
-
if i change the CssClass to form-control both in aspx.cs and in the javascript, the search action can not work, it retu nothing.
<asp:GridView ID="gv_dalamkota"CssClass="table table-bordered" runat="server" BorderColor="#1E6BBC" BorderStyle="None" BorderWidth="1px" CellPadding="3" ShowFooter="True" AutoGenerateColumns="False" AllowPaging="True" OnSelectedIndexChanged="gv_dalamkota_SelectedIndexChanged" OnPageIndexChanging="OnPaging" OnDataBound="OnDataBound"DataSourceID="ds_dalamkota"><RowStyle BackColor="#EFEFEF" /><AlteatingRowStyle BackColor="white" /><PagerStyle CssClass="gridview" /><Columns><asp:BoundField DataField="nond" HeaderText="Nomor ND"SortExpression="nond" /><asp:BoundField DataField="halst" HeaderText="Hal Surat Tugas"SortExpression="halst" /> <asp:TemplateField HeaderText="Jenis Kuitansi"> <ItemTemplate> <asp:DropDownList ID="ddl_jenis_kuitansi" CssClass="btn btn-primary dropdown-toggle" runat="server"> <asp:ListItem Value="1" Text="Dalam Kota 1 Tahap >= 8 Jam"></asp:ListItem> <asp:ListItem Value="2" Text="Dalam Kota 2 Tahap >= 8 Jam"></asp:ListItem> <asp:ListItem Value="3" Text="Dalam Kota 1 Tahap < 8 Jam"></asp:ListItem> </asp:DropDownList> </ItemTemplate> </asp:TemplateField> <asp:CommandField ShowSelectButton="True" ControlStyle-CssClass="btn btn-primary"> <ControlStyle CssClass="btn btn-primary"></ControlStyle> </asp:CommandField> </Columns>`
ASPX.CS
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
for (int i = 0; i < gv_dalamkota.Columns.Count; i++)
{
TableHeaderCell cell = new TableHeaderCell();
TextBox txtSearch = new TextBox();
txtSearch.Attributes["placeholder"] = gv_dalamkota.Columns[i].HeaderText;
txtSearch.CssClass = "search_textbox";
cell.Controls.Add(txtSearch);
row.Controls.Add(cell);
}
gv_dalamkota.FooterRow.Parent.Controls.AddAt(1, row);
}
Java script
<script src='<%# ResolveUrl("~/js/quicksearch.js")%>'></script>
<script src='<%# ResolveUrl("~/js/custom.js")%>'></script>
<script type="text/javascript">
$(function () {
$('.search_textbox').each(function (i) {
$(this).quicksearch("[id*=gv_dalamkota] tr:not(:has(th))", {
'testQuery': function (query, txt, row) {
retu $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
}
});
});
});
</script>
