e14e13c90aa4b8a325f165d44bca1035cd111bb8
galt
  Sat Feb 1 12:40:53 2020 -0800
cirm cdwWebBrowse. Cannot just pass initialwhere, so get it from the cart.

diff --git src/hg/lib/tablesTables.c src/hg/lib/tablesTables.c
index 89cb7cd..dab9121 100644
--- src/hg/lib/tablesTables.c
+++ src/hg/lib/tablesTables.c
@@ -72,31 +72,30 @@
 /* Print instructional text, and basic summary info on who passes filter, and a submit
  * button just in case user needs it */
 {
 /* Print info on matching */
 int matchCount = slCount(table->rowList);
 if (largerContext != NULL)  // Need to page?
      matchCount = largerContext->tableSize;
 
 printf("<input class='btn btn-secondary' type='submit' name='submit' id='submit' value='Search'>");
 
 printf("&nbsp&nbsp;");
 printf("<input class='btn btn-secondary' type='button' id='clearButton' VALUE=\"Clear Search\">");
 jsOnEventById("click", "clearButton",
     "$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');\n"
     "$('[name=cdwBrowseFiles_page]').val('1');\n"
-    "$('[name=clearSearch]').val('1');\n"
     "$('#submit').click();\n");
 
 printf("<br>");
 
 printf("%d&nbsp;%s&nbsp;found. ", matchCount, itemPlural);
 
 if (addFunc)
     addFunc(matchCount);
 
 if (!visibleFacetList)
     {
     printf("<BR>\n");
     printf("You can further filter search results field by field below. ");    
     printf("Wildcard * and ? characters are allowed in text fields. ");
     printf("&GT;min or &LT;max are allowed in numerical fields.<BR>\n");
@@ -382,80 +381,80 @@
 		"$('[name=%s_page]').val('%d');\n"
 		"$('#submit').click();\n"
 		, varPrefix, totalPages);
 
 	    }
 	}
      }
 }
 
 void webFilteredFieldedTable(struct cart *cart, struct fieldedTable *table, 
     char *returnUrl, char *varPrefix,
     int maxLenField, struct hash *tagOutputWrappers, void *wrapperContext,
     boolean withFilters, char *itemPlural, 
     int pageSize, struct fieldedTableSegment *largerContext, struct hash *suggestHash, 
     struct facetField **ffArray, char *visibleFacetList,
-    void (*addFunc)(int), char *initialWhere)
+    void (*addFunc)(int))
 /* Show a fielded table that can be sorted by clicking on column labels and optionally
  * that includes a row of filter controls above the labels .
  * The maxLenField is maximum character length of field before truncation with ...
  * Pass in 0 for no max */
 {
 if (strchr(returnUrl, '?') == NULL)
      errAbort("Expecting returnUrl to include ? in showFieldedTable\nIt's %s", returnUrl);
 
 if (withFilters || visibleFacetList)
     showTableFilterInstructionsEtc(table, itemPlural, largerContext, addFunc, visibleFacetList);
 
 // Show top bar with quick-deselects for selected facet values
 //  as well a clear restriction button that cleans out cdwFile_filter cart var. 
 
 if (visibleFacetList)
     {
+    char *where = cartUsualString(cart, "cdwFile_filter", "");
 
-    if (!isEmpty(initialWhere))
+    if (!isEmpty(where))
 	{
 	// left column
 	printf("<div>\n");
         
-	printf("Restricting files to where %s. ", initialWhere);
+	printf("Restricting files to where %s. ", where);
 
 	printf("&nbsp&nbsp;");
 	printf("<input class='btn btn-secondary' type='button' id='clearRestrictionButton' VALUE=\"Clear Restriction\">");
 	jsOnEventById("click", "clearRestrictionButton",
-	    "$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');\n"
 	    "$('[name=cdwBrowseFiles_page]').val('1');\n"
 	    "$('[name=clearRestriction]').val('1');\n"
 	    "$('#submit').click();\n");
 
 	printf("<br>");
         }
 
     boolean gotSelected = FALSE;
 
     struct slName *nameList = slNameListFromComma(visibleFacetList);
     int f;
     for (f = 0; f < table->fieldCount; ++f) 
 	{
 	struct facetField *field = ffArray[f];
 	if (slNameInListUseCase(nameList, field->fieldName)) // i.e. is this field a visible facet?
 	    {
 	    if (!field->allSelected)
 		{
 		if (!gotSelected)
 		    {
-		    if (isEmpty(initialWhere))  // we still need to do this
+		    if (isEmpty(where))  // we still need to do this
 			{
 			// left column
 			printf("<div>\n");
 			}
 		    htmlPrintf("<dl style='display: inline-block;'>\n");
 		    gotSelected = TRUE;
 		    }
 		htmlPrintf("<span class='card facet-card' style='display: inline-block;'><span class='card-body'>\n");
 		htmlPrintf("<dt style='display: inline-block;'>\n");
 		htmlPrintf("<h6 class='card-title'>%s</h6></dt>\n", field->fieldName);
 
 		struct facetVal *val;
 
 		// Sort values alphabetically
 		// Make a copy to not disturb the original order 
@@ -485,31 +484,31 @@
 			printf("</dd>\n");
 			}
 		    }
 		slFreeList(&valListCopy);
 		
 		htmlPrintf("</span></span>\n");
 
 		}
 
 	    }
 	}
 
     if (gotSelected)
 	htmlPrintf("</dl>\n");
    
-    if (!isEmpty(initialWhere) || gotSelected)
+    if (!isEmpty(where) || gotSelected)
 	printf("</div><br>\n");
 
     }
 
 printf("<div class='row'>\n"); // parent container
 
 if (visibleFacetList)
     {
 
     // left column
     printf("<div class='col-xs-6 col-sm-4 col-md-4 col-lg-3 col-xl-3'>\n");
 
     // reset all facet value selections
     char *op = "resetAll";
     htmlPrintf("<a class='btn btn-secondary' href='../cgi-bin/cdwWebBrowse?%s=%s|url|&cdwCommand=browseFiles"
@@ -659,31 +658,31 @@
     printf("</div>");
 
 printf("</div>\n"); //close parent container
 }
 
 void webSortableFieldedTable(struct cart *cart, struct fieldedTable *table, 
     char *returnUrl, char *varPrefix,
     int maxLenField, struct hash *tagOutputWrappers, void *wrapperContext)
 /* Display all of table including a sortable label row.  The tagOutputWrappers
  * is an optional way to enrich output of specific columns of the table.  It is keyed
  * by column name and has for values functions of type webTableOutputWrapperType. */
 {
 webFilteredFieldedTable(cart, table, returnUrl, varPrefix, 
     maxLenField, tagOutputWrappers, wrapperContext,
     FALSE, NULL, 
-    slCount(table->rowList), NULL, NULL, NULL, NULL, NULL, NULL);
+    slCount(table->rowList), NULL, NULL, NULL, NULL, NULL);
 }
 
 
 void webTableBuildQuery(struct cart *cart, char *from, char *initialWhere, 
     char *varPrefix, char *fields, boolean withFilters, 
     struct dyString **retQuery, struct dyString **retWhere)
 /* Construct select, from and where clauses in query, keeping an additional copy of where 
  * Returns the SQL query and the SQL where expression as two dyStrings (need to be freed)  */
 {
 struct dyString *query = dyStringNew(0);
 struct dyString *where = dyStringNew(0);
 struct slName *field, *fieldList = commaSepToSlNames(fields);
 boolean gotWhere = FALSE;
 sqlDyStringPrintf(query, "select %-s from %-s", sqlCkIl(fields), sqlCkIl(from));
 if (!isEmpty(initialWhere))
@@ -816,22 +815,22 @@
 if (context.tableSize > pageSize)
     {
     int lastPage = (context.tableSize-1)/pageSize;
     if (page > lastPage)
         page = lastPage;
     context.tableOffset = page * pageSize;
     }
 
 if (!visibleFacetList)
     {
     sqlDyStringPrintf(query, " limit %d offset %d", pageSize, context.tableOffset);
     table = fieldedTableFromDbQuery(conn, query->string);
     }
 
 webFilteredFieldedTable(cart, table, returnUrl, varPrefix, maxFieldWidth, 
-    tagOutWrappers, wrapperContext, withFilters, itemPlural, pageSize, &context, suggestHash, ffArray, visibleFacetList, addFunc, initialWhere);
+    tagOutWrappers, wrapperContext, withFilters, itemPlural, pageSize, &context, suggestHash, ffArray, visibleFacetList, addFunc);
 fieldedTableFree(&table);
 
 dyStringFree(&query);
 dyStringFree(&where);
 }