In pentaho dashboard how to display the table component columns using different sql datasources - components

I want to display a table with data coming from different sql tables, like for a single table component, some columns of the table come from one sql query and other column from next query. Using join queries or sub queries will display wrong data. In table component there is only one option for selecting the data-source.
Is there any way to do this?

With Javascript, in the pre-Execution function of the table component, you can change the datasource, but not for single columns.
You can hide some columns in the table component if you want.
How to change the datasource with Javascript
I created a Simple Parameter: refresh_table, and it contains the datasource of the table: sql_Empty, to show an empty table.
I created some Select components and when you choose a value and then you click on the Button component (a search button), the search button changes the value in the simple parameter 'refresh_table' with a new datasource based on the value in the select component: sql_A, sql_B.
function a() {
var a = this.dashboard.getParameterValue('selectA');
var b = this.dashboard.getParameterValue('selectB');
if (a === 'ciao' && b === 'ciao') {
this.dashboard.fireChange('refresh_table', 'sql_A');
} else {
this.dashboard.fireChange('refresh_table', 'sql_B');
}
}
In the preExecution function of the table component, I wrote this function to change the datasource based on the parameter value of refresh_table.
function b() {
this.chartDefinition.dataSource = this.dashboard.getParameterValue('refresh_table');
}

I think you can do it with Pentaho Data Integration/Kettle/Spoon and then you can pass the results to the table component, but I don't know how.

Related

Android Studio Room query to get a random row of db and saving the rows 2nd column in variable

like the title mentions I want a Query that gets a random row of the existing database. After that I want to save the data which is in a specific column of that row in a variable for further purposes.
The query I have at the moment is as follows:
#Query("SELECT * FROM data_table ORDER BY RANDOM() LIMIT 1")
fun getRandomRow()
For now I am not sure if this query even works, but how would I go about writing my function to pass a specific column of that randomly selected row to a variable?
Ty for your advice, tips and/or solutions!
Your query is almost correct; however, you should specify a return type in the function signature. For example, if the records in the data_table table are mapped using a data class called DataEntry, then the query could read as shown below (note I've also added the suspend modifier so the query must be run using a coroutine):
#Query("SELECT * FROM data_table ORDER BY RANDOM() LIMIT 1")
suspend fun getRandomRow(): DataEntry?
If your application interacts with the database via a repository and view model (as described here: https://developer.android.com/topic/libraries/architecture/livedata) then the relevant methods would be along the lines of:
DataRepository
suspend fun findRandomEntry(): DataEntry? = dataEntryDao.getRandomRow()
DataViewModel
fun getRandomRecord() = viewModelScope.launch(Dispatchers.IO) {
val entry: DataEntry? = dataRepository.findRandomEntry()
entry?.let {
// You could assign a field of the DataEntry record to a variable here
// e.g. val name = entry.name
}
}
The above code uses the view model's coroutine scope to query the database via the repository and retrieve a random DataEntry record. Providing the returning DataEntry record is not null (i.e. your database contains data) then you could assign the fields of the DataEntry object to variables in the let block of the getRandomRecord() method.
As a final point, if it's only one field that you need, you could specify this in the database query. For example, imagine the DataEntry data class has a String field called name. You could retrieve this bit of information only and ignore the other fields by restructuring your query as follows:
#Query("SELECT name FROM data_table ORDER BY RANDOM() LIMIT 1")
suspend fun getRandomRow(): String?
If you go for the above option, remember to refactor your repository and view model to expect a String instead of a DataEntry object.

Access List Options for a Field in a Custom Table in Kentico 10

I have a custom table with a few fields that have list options for the user to select from when adding the content. Is there something in the API that allows me to access the options for a particular field so I can use those same options in a filtering widget?
Something like the below but that works for fields in a custom table?
var guids = ParentDocument.GetValue("CustomFieldName").Split(';');
var referencedDocs = DocumentHelper.GetDocuments().WhereIn("DocumentGuid", guids);
UPDATE - The code in case the link in the answer changes:
protected string[] GetFormFieldOptions()
{
DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo("custom.MyPageTypeName");
if (dci != null)
{
//Get the data from the form field
FormInfo fi = new FormInfo(dci.ClassFormDefinition);
FormFieldInfo ffi = fi.GetFormField("Industry");
string[] industries = ffi.Settings["Options"].ToString().Split('\n');
return industries;
}
return null;
}
Use DataClassInfoProvider in order to get data you need. Check this blog post to see more details.
You can use the same code as you have in your question. The difference is you need to get 2 different things which are not available at the "Page" or "Document" level:
Custom table object
Custom table item based on #1
You use the API to get the custom table item:
var cti = CustomTableItemProvider.GetItem(<id or guid>, "yourcustom.tableclassname);
if (cti != null)
{
string[] s = ValidationHelper.GetString(cti.GetValue("YourField"), "").Split(";");
}
Update
To get a dynamic list of options in a field you can simply use a listing control like a dropdown list or a radio button list as your control (vs. a textbox). Then in the properties for the dropdownlist, you can set it to a query. In the query enter something like
-- if you wan to have a 'select one' add this
SELECT '', '-- select one --'
UNION
SELECT ItemID, FieldName
FROM CustomTable_Name
ORDER BY 2

Sparkline not loading in Table component while paginating

I am using Pentaho cde 4.8
I need to show Sparkline and Arrow in my Table component, I am using pagination in my table component.
My sparkline and arrow chart is visible While dashboard is loaded at first. Table component will show 10 rows per page and it will show all the charts as per my column type.
The problem occurs here, if I try to navigate to second page using pagination in my table then the charts are not shown and it will only show the values in the column. the same happens during when I use search bar in my Table component.
This is code I use in preexecution:
function f(){
this.setAddInOptions("colType","trendArrow",function(state){
return {
includeValue: true,
good: function(state) { if(state.value<=100) return false; else return true;}
};
});
}
I can see sparkline and trend arrow during 1st load like below:
After page navigation, it becomes like this
Avinash,
Try using Draw function.
The same code of preexecution is to be copied in Draw function.
If you need to read API details: https://datatables.net/reference/api/draw%28%29

How do you determine which row was selected in a Infragistics WebHierarchicalDataGrid when you have a Master Detail table configuration

I have a master table and two child detail tables under the master. When the user selects one of the detail tables the RowSelection event fires. I need to determine which table was selected. If the users selectes the second detail table then I need to obtain the data from a specific field. What code can be put in place to make this determination. Here is the code I have so far to grab the data, I just need to build the IF statment around this code.
String UploadIndex;
if (e.CurrentSelectedRows.Count > 0)
{
GridRecord oRow = e.CurrentSelectedRows[0];
UploadIndex = oRow.Items[0].Value.ToString();
}
Tried this but got controlmain is inaccessible due to its protection level.
ContainerGrid oRowIsland = WebHierarchicalDataGrid1.GridView.Rows[e.CurrentSelectedRows[0].Index].RowIslands[0];
if (oRow.Owner.ControlMain.ID == '2')
{
UploadIndex = oRow.Items[0].Value.ToString();
}
Use ContainerGridRecord type instead of GridRecord when declaring oRow, this way you will have access to oRow.Owner.ControlMain which is the grid that holds the row. In debug determine ID of the grid you're interested in and then you can do
If (oRow.Owner.ControlMain.ID == '...ID of second grid') {
// profit
}
Or use some other easily identifiable property of ControlMain grid that in your case assocciate with the second details.

Pass table name a parameter to the Data Context method using LINQ to SQL in C#

I have created a method which delete data from the database by joining a db column with a csv file, I have a list of tables in a Data Context which I need to iterate, i means that I need to change the table name by passing it as parameter to the method.
Basically I need to use this method for all the table present in the Data Context
Current hard coded Table name in a GetTable method: dw_Job
DataContext Object: job
Here is my code
var query = from line in File.ReadAllLines(file, Encoding.GetEncoding(1252))
//let jobrecord = line.Split(',')
join j in job.GetTable<dw_Job>() on
Convert.ToInt32(line.Split(',').GetValue(factColPos))
equals j.JobID
select j;
foreach (var deletejob in query)
{
Console.WriteLine(deletejob);
job.dw_Jobs.DeleteOnSubmit(deletejob);
}
job.SubmitChanges();
I can able to provide if you need any further details of my code. Please correct me on this
Thanks in advance

Resources