Index: pgadmin/include/frm/frmEditGrid.h
===================================================================
--- pgadmin/include/frm/frmEditGrid.h	(revision 7027)
+++ pgadmin/include/frm/frmEditGrid.h	(working copy)
@@ -122,6 +122,7 @@
     int GetNumberStoredRows();
     int GetNumberCols();
     wxString GetColLabelValue(int col);
+    wxString GetColLabelValueUnformatted(int col);
     wxString GetRowLabelValue(int row);
     wxGridCellAttr* GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind);
 
@@ -214,9 +215,16 @@
     void OnEditorHidden(wxGridEvent& event);
     void OnKey(wxKeyEvent& event);
     void OnCopy(wxCommandEvent& event);
+    void OnIncludeFilter(wxCommandEvent& event);
+    void OnExcludeFilter(wxCommandEvent& event);
+    void OnRemoveFilters(wxCommandEvent& event);
+    void OnAscSort(wxCommandEvent& event);
+    void OnDescSort(wxCommandEvent& event);
+    void OnRemoveSort(wxCommandEvent& event);
     void OnPaste(wxCommandEvent& event);
     void OnLabelDoubleClick(wxGridEvent& event);
     void OnLabelRightClick(wxGridEvent& event);
+    void OnCellRightClick(wxGridEvent& event);
     void Abort();
     void OnToggleScratchPad(wxCommandEvent& event);
     void OnToggleLimitBar(wxCommandEvent& event);
@@ -230,7 +238,7 @@
     frmMain *mainForm;
     pgConn *connection;
     pgQueryThread *thread;
-    wxMenu *fileMenu, *editMenu, *viewMenu, *helpMenu;
+    wxMenu *fileMenu, *editMenu, *viewMenu, *toolsMenu, *helpMenu;
     wxToolBar *toolBar;
     ctlComboBoxFix *cbLimit;
     wxTextCtrl *scratchPad;
Index: pgadmin/include/frm/menu.h
===================================================================
--- pgadmin/include/frm/menu.h	(revision 7027)
+++ pgadmin/include/frm/menu.h	(working copy)
@@ -46,6 +46,12 @@
     MNU_OPTIONS,
     MNU_CUT,
     MNU_COPY,
+    MNU_INCLUDEFILTER,
+    MNU_EXCLUDEFILTER,
+    MNU_REMOVEFILTERS,
+    MNU_ASCSORT,
+    MNU_DESCSORT,
+    MNU_REMOVESORT,
     MNU_PASTE,
     MNU_CLEAR,
     MNU_FIND,
Index: pgadmin/frm/frmEditGrid.cpp
===================================================================
--- pgadmin/frm/frmEditGrid.cpp	(revision 7027)
+++ pgadmin/frm/frmEditGrid.cpp	(working copy)
@@ -59,6 +59,12 @@
     EVT_MENU(MNU_REFRESH,       frmEditGrid::OnRefresh)
     EVT_MENU(MNU_DELETE,        frmEditGrid::OnDelete)
     EVT_MENU(MNU_SAVE,          frmEditGrid::OnSave)
+    EVT_MENU(MNU_INCLUDEFILTER, frmEditGrid::OnIncludeFilter)
+    EVT_MENU(MNU_EXCLUDEFILTER, frmEditGrid::OnExcludeFilter)
+    EVT_MENU(MNU_REMOVEFILTERS, frmEditGrid::OnRemoveFilters)
+    EVT_MENU(MNU_ASCSORT,       frmEditGrid::OnAscSort)
+    EVT_MENU(MNU_DESCSORT,      frmEditGrid::OnDescSort)
+    EVT_MENU(MNU_REMOVESORT,    frmEditGrid::OnRemoveSort)
     EVT_MENU(MNU_UNDO,          frmEditGrid::OnUndo)
     EVT_MENU(MNU_OPTIONS,       frmEditGrid::OnOptions)
     EVT_MENU(MNU_HELP,          frmEditGrid::OnHelp)
@@ -76,6 +82,7 @@
     EVT_GRID_SELECT_CELL(       frmEditGrid::OnCellChange)
     EVT_GRID_EDITOR_SHOWN(      frmEditGrid::OnEditorShown)
     EVT_GRID_EDITOR_HIDDEN(     frmEditGrid::OnEditorHidden)
+    EVT_GRID_CELL_RIGHT_CLICK(  frmEditGrid::OnCellRightClick)
     EVT_GRID_LABEL_RIGHT_CLICK( frmEditGrid::OnLabelRightClick)
     EVT_AUI_PANE_BUTTON(        frmEditGrid::OnAuiUpdate)
 END_EVENT_TABLE()
@@ -171,14 +178,25 @@
     viewMenu = new wxMenu();
     viewMenu->Append(MNU_REFRESH, _("&Refresh\tF5"),_("Refresh."));
     viewMenu->AppendSeparator();
-    viewMenu->Append(MNU_OPTIONS, _("&Sort/filter..."),_("Sort/filter options."));
-    viewMenu->AppendSeparator();
     viewMenu->Append(MNU_LIMITBAR, _("&Limit bar\tCtrl-Alt-L"), _("Show or hide the row limit options bar."), wxITEM_CHECK);
     viewMenu->Append(MNU_SCRATCHPAD, _("S&cratch pad\tCtrl-Alt-S"), _("Show or hide the scratch pad."), wxITEM_CHECK);
     viewMenu->Append(MNU_TOOLBAR, _("&Tool bar\tCtrl-Alt-T"), _("Show or hide the tool bar."), wxITEM_CHECK);
     viewMenu->AppendSeparator();
     viewMenu->Append(MNU_DEFAULTVIEW, _("&Default view\tCtrl-Alt-V"),     _("Restore the default view."));
 
+	
+    // Tools menu
+    toolsMenu = new wxMenu();
+    toolsMenu->Append(MNU_OPTIONS, _("&Sort / Filter ..."),_("Sort / Filter options."));
+    toolsMenu->AppendSeparator();
+    toolsMenu->Append(MNU_INCLUDEFILTER, _("Filter By &Selection"),_("Display only those rows that have this value in this column."));
+	toolsMenu->Append(MNU_EXCLUDEFILTER, _("Filter E&xcluding Selection"),_("Display only those rows that do not have this value in this column."));
+	toolsMenu->Append(MNU_REMOVEFILTERS, _("&Remove Filter"),_("Remove all filters on this table"));
+	toolsMenu->AppendSeparator();
+	toolsMenu->Append(MNU_ASCSORT, _("Sort &Ascending"),_("Append an ASCENDING sort condition based on this column"));
+	toolsMenu->Append(MNU_DESCSORT, _("Sort &Descending"),_("Append a DESCENDING sort condition based on this column"));
+	toolsMenu->Append(MNU_REMOVESORT, _("&Remove Sort"),_("Remove all sort conditions"));
+	
     // Help menu
     helpMenu = new wxMenu();
     helpMenu->Append(MNU_CONTENTS, _("&Help contents"),_("Open the helpfile."));
@@ -188,6 +206,7 @@
     menuBar->Append(fileMenu, _("&File"));
     menuBar->Append(editMenu, _("&Edit"));
     menuBar->Append(viewMenu, _("&View"));
+    menuBar->Append(toolsMenu,_("&Tools"));
     menuBar->Append(helpMenu, _("&Help"));
     SetMenuBar(menuBar);
 
@@ -388,6 +407,32 @@
 }
 
 
+void frmEditGrid::OnCellRightClick(wxGridEvent& event)
+{
+	wxMenu *xmenu = new wxMenu();
+	
+	sqlGrid->SetGridCursor(event.GetRow(), event.GetCol());
+	
+	xmenu->Append(MNU_INCLUDEFILTER, _("Filter By &Selection"),_("Display only those rows that have this value in this column."));
+	xmenu->Append(MNU_EXCLUDEFILTER, _("Filter E&xcluding Selection"),_("Display only those rows that do not have this value in this column."));
+	xmenu->Append(MNU_REMOVEFILTERS, _("&Remove Filter"),_("Remove all filters on this table"));
+	xmenu->InsertSeparator(3);
+	xmenu->Append(MNU_ASCSORT, _("Sort &Ascending"),_("Append an ASCENDING sort condition based on this column"));
+	xmenu->Append(MNU_DESCSORT, _("Sort &Descending"),_("Append a DESCENDING sort condition based on this column"));
+	xmenu->Append(MNU_REMOVESORT, _("&Remove Sort"),_("Remove all sort conditions"));
+	xmenu->InsertSeparator(7);
+	
+	xmenu->Enable(MNU_INCLUDEFILTER, true);
+	xmenu->Enable(MNU_EXCLUDEFILTER, true);
+	xmenu->Enable(MNU_REMOVEFILTERS, true);
+	xmenu->Enable(MNU_ASCSORT, true);
+	xmenu->Enable(MNU_DESCSORT, true);
+	xmenu->Enable(MNU_REMOVESORT, true);
+	
+	sqlGrid->PopupMenu(xmenu);
+}
+
+
 void frmEditGrid::OnCellChange(wxGridEvent& event)
 {
     sqlTable *table=sqlGrid->GetTable();
@@ -416,6 +461,149 @@
 }
 
 
+void frmEditGrid::OnIncludeFilter(wxCommandEvent &event)
+{
+	int curcol=sqlGrid->GetGridCursorCol();
+	int currow=sqlGrid->GetGridCursorRow();
+	
+	sqlTable *table=sqlGrid->GetTable();
+	wxString column_label = table->GetColLabelValueUnformatted(curcol);
+	wxString new_filter_string;
+	
+	size_t old_filter_string_length = GetFilter().Trim().Len();
+	
+	if (old_filter_string_length > 0) {
+		new_filter_string = GetFilter().Trim() + wxT(" \n    AND ");
+	}
+		
+	if (table->IsColText(curcol)) {
+		
+		if (sqlGrid->GetCellValue(currow, curcol).IsNull()) {
+			new_filter_string += column_label + wxT(" IS NULL ");
+		} else {
+			
+			if (sqlGrid->GetCellValue(currow, curcol) == wxT("\'\'")) {
+				new_filter_string += column_label + wxT(" = ''");
+			} else {
+				new_filter_string += column_label + wxT(" = '") + sqlGrid->GetCellValue(currow, curcol) + wxT("' ");
+			}
+		}
+	} else {
+		
+		if (sqlGrid->GetCellValue(currow, curcol).IsNull()) {
+			new_filter_string += column_label + wxT(" IS NULL ");
+		} else {
+			new_filter_string += column_label + wxT(" = ") + sqlGrid->GetCellValue(currow, curcol);
+		}
+	}
+	
+	SetFilter(new_filter_string);
+	
+	Go();
+}
+
+
+void frmEditGrid::OnExcludeFilter(wxCommandEvent &event)
+{
+	int curcol=sqlGrid->GetGridCursorCol();
+	int currow=sqlGrid->GetGridCursorRow();
+	
+	sqlTable *table=sqlGrid->GetTable();
+	wxString column_label = table->GetColLabelValueUnformatted(curcol);
+	wxString new_filter_string;
+	
+	size_t old_filter_string_length = GetFilter().Trim().Len();
+	
+	if (old_filter_string_length > 0) {
+		new_filter_string = GetFilter().Trim() + wxT(" \n    AND ");
+	}
+	
+	if (table->IsColText(curcol)) {
+		if (sqlGrid->GetCellValue(currow, curcol).IsNull()) {
+			new_filter_string += column_label + wxT(" IS NOT NULL ");
+		} else {
+			
+			if (sqlGrid->GetCellValue(currow, curcol) == wxT("\'\'")) {
+				new_filter_string += column_label + wxString::Format(_(" <> '' ")) ;
+			} else {
+				new_filter_string += column_label + wxT(" <> '") + sqlGrid->GetCellValue(currow, curcol) + wxT("' ");
+			}
+		}
+	} else {
+		
+		if (sqlGrid->GetCellValue(currow, curcol).IsNull()) {
+			new_filter_string += column_label + wxT(" IS NOT NULL ") ;
+		} else {
+			new_filter_string += column_label + wxT(" <> ") + sqlGrid->GetCellValue(currow, curcol);
+		}
+	}
+
+	SetFilter(new_filter_string);
+	
+	Go();
+}
+
+
+void frmEditGrid::OnRemoveFilters(wxCommandEvent &event)
+{
+	SetFilter(wxT(""));
+	
+	Go();
+}
+
+
+void frmEditGrid::OnAscSort(wxCommandEvent &ev)
+{
+	int curcol=sqlGrid->GetGridCursorCol();
+	
+	sqlTable *table=sqlGrid->GetTable();
+	wxString column_label = table->GetColLabelValueUnformatted(curcol);
+	wxString new_sort_string;
+	
+	size_t old_sort_string_length = GetSortCols().Trim().Len();
+	
+	if (old_sort_string_length > 0) {
+		new_sort_string = GetSortCols().Trim() + wxT(" , ");
+	}
+	
+	new_sort_string += column_label + wxT(" ASC ");
+	
+	SetSortCols(new_sort_string);
+	
+	Go();
+}
+
+
+void frmEditGrid::OnDescSort(wxCommandEvent &ev)
+{
+	int curcol=sqlGrid->GetGridCursorCol();
+	
+	sqlTable *table=sqlGrid->GetTable();
+	wxString column_label = table->GetColLabelValueUnformatted(curcol);
+	wxString new_sort_string;
+	
+	size_t old_sort_string_length = GetSortCols().Trim().Len();
+	
+	if (old_sort_string_length > 0) {
+		new_sort_string = GetSortCols().Trim() + wxT(" , ");
+	}
+	
+	new_sort_string += column_label + wxT(" DESC ");
+	
+	SetSortCols(new_sort_string);
+	
+	Go();
+}
+
+
+void frmEditGrid::OnRemoveSort(wxCommandEvent &ev)
+{
+	SetSortCols(wxT(""));
+	
+	Go();
+}
+
+
 void frmEditGrid::OnCopy(wxCommandEvent &ev)
 {
     wxWindow *wnd=FindFocus();
@@ -746,6 +934,7 @@
 	if (optionsChanged) Go();
 }
 
+
 template < class T >
 int ArrayCmp(T *a, T *b)
 {
@@ -1994,6 +2183,12 @@
 }
 
 
+wxString sqlTable::GetColLabelValueUnformatted(int col)
+{
+    return columns[col].name;
+}
+
+
 wxString sqlTable::GetRowLabelValue(int row)
 {
     wxString label;
Index: pgadmin/dlg/dlgEditGridOptions.cpp
===================================================================
--- pgadmin/dlg/dlgEditGridOptions.cpp	(revision 7027)
+++ pgadmin/dlg/dlgEditGridOptions.cpp	(working copy)
@@ -187,6 +187,7 @@
     OnLstSortColsChange(nullLstEvent);
 }
 
+
 void dlgEditGridOptions::OnAsc(wxCommandEvent &ev)
 {
     long itm = lstSortCols->GetItemCount();
