Tabulator 5.2 New editor List option/value - tabulator

In the new tabulator v5.2, the editor "select" was changed to "list", I have this code that was working fine in v5.1 but stop working in the new version, I hope someone can help me figured out what do I need to change to make it work again with this new version of tabulator.
Ex: in my table there are two columns with select dropdown values, the second column is dependent on the first. So if I select "Sales" in the first column, in the same row on the second column it will only show a list of "services" that belongs to the "Sales" department and so on.
In the code linked below you can see that in the first column when I click in a row in the "Dept" column, a list of values shows up, and if I select the value "Sales" it change to option "1".
{title:"DEPT", field:"dept", width:90, hozAlign:"left", editor:"list", editorParams:{values: {1:"Sales",2:"Service",3:"Bodyshop",4:"Carwash"}}},
{title:"WORK Type", field:"service", editor:"list", editorParams:{values: serviceList}},
jsfiddle

You can use the built-in lookup formatter to do that:
columns:[
{title:"DEPT", field:"dept",
width:90, hozAlign:"left",
editor:"list",
editorParams:{
values: {1:"Sales",2:"Service",3:"Bodyshop",4:"Carwash"}
},
formatter:"lookup",
formatterParams:{
1:"Sales", 2:"Service", 3:"Bodyshop", 4:"Carwash"
}},
Passing the same object of editorParams into the formatterParams would do your job.
Working Demo: https://jsfiddle.net/Mahesh1312/rzbxvym7/5/
Hope it helps!

Related

Power Query excel

i am trying to use a if formula in power query. For example, if the Column contains “guy” then value is male and the false value is “female”. I tried different ways and I can’t find the right formula to use in power query. Can anyone help me please?
If you are entering this into the Add Custom Column dialog, something like (for case-insensitive):
= if Text.Contains([Column],"guy", Comparer.OrdinalIgnoreCase) then "male" else "female"
It sounds like you are wanting to conditionally replace values in a column, based on the existing values in that column? If so, you can use the Table.ReplaceValue function in Power Query:
= Table.ReplaceValue(Source,
each [Gender],
each if [Gender] = "guy" then "male" else "female",
Replacer.ReplaceText,{"Gender"})
That will change all values of "guy" to "male', and ALL other values to "female", as you stated.
You can also leave values in place that don't meet the criteria, by simply referencing the column name instead of a specifying a new value:
= Table.ReplaceValue(Source,
each [Gender],
each if [Gender] = "guy" then "male" else [Gender],
Replacer.ReplaceText,{"Gender"})
Create a table with a column called Gender, and load it to power query. Right-click on the column header and choose Replace Values to get the UI to build your statement for you, then replace the generated code with the above modification(s) and apply to your actual requirements. The key is using the each expression to tell Power Query to test at the row value level. If you omit each, you'll see the error:
"Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"
= Table.AddColumn(#"Changed Type","ColumnName",each if[Column] ="""Guy""" then"""Male""" else"""Female""")

Tabulator: Have a value associated with cell

I am deciding to use this wonderful Tabulator js library but I want to have a different value associated with each cell value that is displayed.
Like
<td value="1">Bob</td>
I see the below options for setting a drop down
columns:[
{title:"Name", field:"name", editor:"select", editorPramas: names
]
where names = { 1: 'Bob', 2: 'Jack'}
however this results in bob and Jack being displayed in the drop down and when Bob is selected it displays 1 in the cell value. However I want Jack and Bob to be in dropdown and when Bob is selected data cell gets value of 1 because I have columns values mapped to IDs which need to be stored in database.
This can be done by custom editorParams
columns:[
{title:"Name", field:"name", editor:"select", editorPramas: myCustom
]
var myCustom = function(cell) {
cell.getElement().setAttribute("value",2);
...
}
whereby one can get the cell element which is changed and accordingly change any attribute of it.
I believe this feature should be considered and generic in the next release.
I proposed a hack for the input editor but this should be done in a generic way with the new parameter elementProps
https://github.com/olifolkerd/tabulator/issues/1869

Tabulator update column position programmatically?

Is it possible to update column position with Tabulator?
Or is there a way to do it?
Apparently there is no function to do it.
A moveColumn function will be coming in the 4.2 release next week.
In the mean time you can easily change the order of columns in the table by calling the deleteColumn function and then the addColumn function.
//remove column
table.deleteColumn("age");
//add column elsewhere in the table after the name column
table.addColumn({title:"Age", field:"age"}, "name");
or by changing the column definition array and resubmitting it using the setColumns function
//define new column layout
var columns = [
{title:"Name", field:"name"},
{title:"Age", field:"age"},
{title:"Gender", field:"gender"},
]
//replace all columns
table.setColumns(columns);
Full documentation on these features can be found in the Columns Documentation

Power Query - Keeping Most recent records in change log columns

I need to strip records to show just the most recent for a given person, and I'm trying to think of a method for doing this in a custom column so I can just keep the most recent records. This is essentially a a status change list, and I need to match the last change as a "current status" for merging with another query. Each date can be unique, and each person can have any from 1 to a dozen status changes. I've picked a selection below, Last Names have been removed to protect the innocent. For sake of the example, Each "name" has a unique identifier that I can use to prevent any overlap from similar names.
AaronS 4/1/2015
AaronS 10/16/2013
AaronS 5/15/2013
AdamS 2/27/2007
AdamL 12/16/2004
AdamL 11/17/2004
AlanG 11/1/2007
AlexanderJ 7/1/2016
AlexanderJ 1/25/2016
AlexanderJ 4/1/2015
AlexanderJ 10/16/2013
AlexanderJ 6/1/2013
AlexanderJ 11/7/2011
My goal would be to return the most recent date for each individual "name" and nulls for the other rows. Then I can filter out nulls to return one row per name. I'm fairly new to power query and mostly adept with the UI, barely learning M Code. Any help will be most welcome.
GUI
Bring the "Name" and "Date" data into Power Query.
Group by "Name". In the Group By dialog select the operation All Rows. Name the new column "AllRows". Click OK.
Add a custom column and title it "LatestRow". Enter the formula below. Click OK. Note that the "Date" column is coming from the sub-table in the "AllRows" column.
= Table.Max([AllRows], "Date")
Click the expand button in the upper right corner of the "LatestRow" column. This will return the record associated with the latest date for each name.
Code
let
Source = Excel.CurrentWorkbook(){[Name="data"]}[Content],
GroupedRows = Table.Group(Source, {"Name"}, {{"AllRows", each _, type table [Name=nullable text, Date=nullable datetime]}}),
AddedCustomColumn = Table.AddColumn(GroupedRows, "LatestRow", each Table.Max([AllRows], "Date")),
ExpandedLatestRow = Table.ExpandRecordColumn(AddedCustomColumn, "LatestRow", {"Date"}, {"LatestRow.Date"})
in
ExpandedLatestRow

Searching controls dynamically by adding search properties in code

I am trying to identify controls at runtime by adding some search properties in my code as and when required. Using Coded UI in Visual Studio 2012.
Please refer to the screenshot below. My test scenario is:
1) Click on a particular tab (the 2nd tab selected in the screenshot)
The Tab list is fixed so I can create one control in My UIMap for each tab.
2) Inside every Tab, there is a tabular structure with some data. The Table headings are fixed but the number of rows and the data inside the rows is dynamic.
3) Check the checkBox for the required tag
4) Select Type for required tag
I have created my UIMap as:
Added following code:
UIEquipmentTagText.SearchProperties.Add(new PropertyExpression(WpfText.PropertyNames.Name, "1302"));// say I want second row
To fetch the respective checkbox control, I am using:
UITestControl UIEquipmentTagCell = UIEquipmentTagText.GetParent();//get the cell of Tag name
UITestControl UIEquipmentTagRow = UIEquipmentTagCell.GetParent();//get the row
UITestControl UIEquipmentCheckBoxCell = UIEquipmentTagRow.GetChildren()[0];//get the first cell i.e the checkbox cell
UITestControl UIEquipmentCheckBox = UIEquipmentCheckBoxCell.GetChildren()[0]; // get the checkbox control
But this is not working for me. I guess the UIRow control is referring to first row only (though I haven’t specified to look for 1st row)
I do not want to include row number in my search criteria for Row.
Is there any workaround to get all the controls I want based on the Tag Text only?
figured out a solution finally..get all rows and iterate to find the matching row
UITestControlCollection allRows = row.FindMatchingControls();
foreach (UITestControl x in allRows)
{
UITestControl Tag = x.GetChildren()[1].GetChildren()[0];//row->tag cell->tag text
if (Tag.GetProperty("Name").Equals("1302"))//say I want to select row having 1302 tag
{
UITestControl checkBox = Tag.GetParent().GetParent().GetChildren()[0].GetChildren()[0];//TagText->TagCell->Row->CheckBoxCell->Checkbox
Mouse.Click(checkBox);
}
}

Resources