I'm using javascript to filter my gridview and it works great. The problem is when I click on the gridview to edit an item, it postback and the filtered table is now unfiltered. How can I keep the state of the gridview when using the javascript filter?
Javascript:
<script type="text/javascript">
function myFunction() {
//Searcing the table
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("<%=txtSearch.ClientID %>");
filter = input.value.toUpperCase();
table = document.getElementById("<%=gridList.ClientID %>");
tr = table.getElementsByTagName("tr");
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
if (td.length > 0) { // to avoid th
//Search the specific column
if (
td[0].innerHTML.toUpperCase().indexOf(filter) > -1 ||
td[1].innerHTML.toUpperCase().indexOf(filter) > -1 ||
td[2].innerHTML.toUpperCase().indexOf(filter) > -1 ||
td[3].innerHTML.toUpperCase().indexOf(filter) > -1 ||
td[4].innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script>
ASP:
<asp:TextBox ID="txtSearch" runat="server" class="form-control" Visible="true" Width="250px" placeholder="Enter Search Term..." onkeyup="myFunction()"/>
<asp:GridView ID="gridList" runat="server" HorizontalAlign="left" ShowHeader="True" AutoGenerateColumns="false" GridLines="None"
OnRowEditing="gridList_RowEditing" OnRowCancelingEdit="gridListt_RowCancelingEdit" OnRowUpdating="gridList_RowUpdating">
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign="left" HeaderText="User">
<ItemTemplate>
<asp:Label ID="user" Visible="true" runat="server" Text='<%# Eval("User") %> ' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtUser" class="form-control" runat="server" Text='<%# Eval("User") %> '></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" HeaderText="Modify"
EditText="<span style='font-size: 20px; color: #27ae60;'><span class='glyphicons glyph-edit'></span></span>"
DeleteText="<span style='font-size: 18px; color: #c0392b;'><span class='glyphicons glyph-bin'></span></span>"
CancelText="<span style='font-size: 20px; color: #7f8c8d;'><span class='glyphicons glyph-remove-2'></span></span>"
UpdateText="<span style='font-size: 20px; color: #2980b9;'><span class='glyphicons glyph-floppy-saved'></span></span>" />
</Columns>
</asp:GridView>
c# editing a row for example:
protected void gridListt_RowEditing(object sender, GridViewEditEventArgs e)
{
gridListGiftList.EditIndex = e.NewEditIndex;
//I need to somehow load the filtered javascript state of the table here rather than the full table
DataSet dsList = objuser.GetList(0);
gridList.DataSource = dsList.Tables[0];
gridList.DataBind();
}