使用自訂過濾應用程式過濾資料表大家好,
我正在建立一個應用程式/儀表板,其中包含一堆報告。最後,我想為用戶提供對主資料表進行「查詢」的選項,並在以後需要時保存它。
目前,我有一個按鈕可以打開另一個視窗並提示使用者選擇過濾列(從預選清單中)。
選擇它們後,他們按下另一個按鈕,該按鈕將為每個過濾列建立一個列錶框,其中包含所有可用的不同值。我的想法是,從這裡用戶將選擇他們希望在每個列錶框中進行過濾的值,然後按最後一個按鈕來保存這些值,然後將建立一個過濾器/where 子句,它將對主資料表進行子集化並保存在一個已知的位置為他們提供。
我相信我已經成功了一半。我讓第一個視窗和過濾器列選擇起作用。然後我可以在列錶框中顯示值,但無法建立右側按鈕來保存這些選定的值。另外,我相信我遇到了不知道用戶將創建多少個過濾器列的問題,因此我必須有一個表達式來定義未知數量的列。我看到了一些 Eval(Parse(Eval Into statements) 的例子,但還沒有得到它。
任何幫助將不勝感激。也許有一種更簡化的方法來做到這一點。
這是我到目前為止的一些程式碼
filter_col_append_expr = Expr(
lub1 << Append(List Box(column(dt1,Char(col_filter[count_i])) <<GETASMATRIX></GETASMATRIX>
//The button which will run the whole thing is here. Some code is ommited
Panel Box("Database Query", Button Box("Query",query_expr;query_window << Append(bb3 = Button Box("Select Filter Values",query_values = lub1<<GET selected=""></GET><BR /><LINGO-LABS id="lingo-labs-828278" slang="en-US" mode="CREATE"><LINGO-LABEL>自動化和腳本編寫</LINGO-LABEL><LINGO-LABEL>數據探索和視覺化</LINGO-LABEL><LINGO-LABEL>視窗</LINGO-LABEL></LINGO-LABS>回覆:使用自訂過濾應用程式過濾資料表您是否考慮過根據使用者選擇的列建立資料過濾器?
回覆:使用自訂過濾應用程式過濾資料表是的,但越雜亂越好,因為沒有多少用戶是 JMP 的新用戶,我希望讓他們盡可能輕鬆地進行視覺化,並透過按按鈕即可取得過濾後的資料。
使用本地過濾器也可以工作
回覆:使用自訂過濾應用程式過濾資料表我會建立資料過濾器(如果需要,您可以清理它),但這是使用列錶框的一種選擇
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
options = dt << Get Column Names("String");
filter_col_append_expr = Expr(
Summarize(dt, colvals = By(Eval(selection))); // Note that Summarize this will change numeric values to strings
lub1 << Append(List Box(colvals));
);
query_expr = Expr(
query_window = New Window("Database Query",
Spacer Box(size(1, 5)),
vlb3 = V List Box(
Text Box("Select All Filter Columns"),
H List Box(
Spacer Box(size(1, 5)),
lb3 = List Box(
options,
max selected(8)
)
),
Spacer Box(size(1, 10)),
Button Box("Select Filter Columns",
cols = lb3 << get selected;
Try(lub1 << Delete Box());
lub_collector << Append(lub1 = Lineup Box(N Col(4)));
For Each({selection}, cols,
filter_col_append_expr
);
),
lub_collector = V List Box();
)
)
);
//The button which will run the whole thing is here. Some code is ommited
nw = New Window("",
Panel Box("Database Query",
Button Box("Query",
query_expr;
query_window << Append(
bb3 = Button Box("Select Filter Values",
vals = (lub1 << XPath("//ListBoxBox")) << get selected;
user_selections = Associative Array(cols, vals);
show(user_selections);
)
);
)
)
);
回覆:使用自訂過濾應用程式過濾資料表謝謝,這符合我的預期。
然而,下一步我就有點陷入僵局了。
為了建立資料過濾器,我正在考慮直接將關聯數組與使用者選擇放在一起,但這不起作用。
然後我考慮將其分解到數據過濾器中,並使用Expr 和其他字串命令來構建它,看起來就像我在構建交互式數據過濾器後使用了紅色三角形一樣,但我認為我在某個地方出錯了句法。
這是我的 BigClass 範例中的程式碼
where_clause_list = {};
where_clause = "";
keys = user_selections << getkeys;
values = user_selections << getvalues;
For ( i=1, i<=NItems(keys), i++,
// Inner loop iterating over items for each category
For Each( {value}, values[i],
// Action for each category-item pair
(where_clause = where_clause || ":"||keys[i] || " ==" || " " || Char(value) || " &"|| " ");
InsertInto(where_clause_list, where_clause);
where_clause = "";));
where_clause="";
For Each({where},where_clause_list,where_clause=where_clause||where);
where_clause = Left(where_clause,Length(where_clause) -3);
Show(where_clause_list);
Show(where_clause);
where_expr = Expr(where_clause);
key_clause="";
For Each({key},keys,key_clause=key_clause||"Ascolumn("||key||")"||" ,");
key_clause = Left(key_clause,Length(key_clause) -2);
keys_expr=Expr(key_clause);
Show(key_clause);
dt << Data Filter(Add Filter(columns(key_expr),Where(where_expr),
Mode( Select( 0 ), Show( 1 ), Include( 1 ))));
然而,有沒有更直接、更直覺的方法來做到這一點呢?
回覆:使用自訂過濾應用程式過濾資料表如果關聯數組中已有選擇,是否還需要資料過濾器?我之前使用資料過濾器的建議是避免創建“額外”列錶框來選擇行值。
回覆:使用自訂過濾應用程式過濾資料表一旦我有了選擇(列名和值),我想對資料進行子集化並僅提取使用者選擇過濾的內容。為此我需要一些數據過濾器,對吧?
回覆:使用自訂過濾應用程式過濾資料表根據「提取」的含義,您可以使用<<來取得行位置+子集或<<選擇位置+子集或<<選擇位置+隱藏和排除
回覆:使用自訂過濾應用程式過濾資料表是的,我確實想使用其中一些方法,但當我不知道用戶選擇了哪一列和值時,不確定如何執行。現在,選擇位於關聯數組中,但將它們轉換為Where 子句對我來說很困難。這就是為什麼我嘗試使用我之前展示的程式碼區塊來建立Where 子句,但我沒有完成它。也許有一種更直接的方法來使用關聯數組來建構 where 子句
回覆:使用自訂過濾應用程式過濾資料表直接使用資料過濾器將是最簡單的選擇,但我們已經排除了這種可能性。使用者選擇應該透過 AND 還是 OR 組合?
回覆:使用自訂過濾應用程式過濾資料表這裡有一些選項
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
// Build using Select Where (simplest)
// Note that we convert to Char due to using Summary and because we can have numeric values
// This could (and should) be handled earlier in some other method
user_selections = ["age" => {"13", "14"}, "sex" => {"F"}];
For Each({{col, values}, idx}, user_selections,
If(idx == 1,
dt << Select Where(Contains(values, Char(Column(dt, col)[])));
);
dt << Select Where(Contains(values, Char(Column(dt, col)[])), Current Selection("restrict")); // AND
// dt << Select Where(Contains(values, Char(Column(dt, col)[])), Current Selection("extend")); // OR
);
show(dt << get selected rows);
wait(1); // demo purposes
dt << Clear Select;
// A bit more complicated is to build expression and use that
user_selections = ["age" => {13, 14}, "sex" => {"F"}]; // simplified to use numeric value for numeric column
filter_expr = Expr(And()); // optionally use Or()
For Each({{col, values}, idx}, user_selections,
cur_expr = Substitute(
Expr(Contains(_list_, _column_)),
Expr(_list_), values,
Expr(_column_), Name Expr(AsColumn(dt, col))
);
Insert Into(filter_expr, Name Expr(cur_expr));
);
// Show(Name Expr(filter_expr));
my_rows = dt << Get Rows Where(filter_expr);
show(my_rows);