How to update rows / set row data in server side row model type in ag grid? - ag-grid

My data model looks like this. Array of objects containing title and created_date.
{
title : String
created_date: Date
}
I have defined a column definition which only renders the title. However, I'd like to sort the rows based on the created_date, without creating a created_date column. There will be an external button detached from the table, which will call the api to get the data. I am using row model type serverSide. I have the sorted data from the backend. I just need to update the data / refresh the data. How can I achieve this ? I have so far tried setRowData(updatedRows). but its giving me an error saying cannot call setRowData unless using normal row model. Is there any way to update my rows in this serverSide row model type settings ?

Calling this.gridApi.setServerSideDatasource(myDataSource); and passing in your dataSource will do the trick. Check here for details

Related

Parse ClassFormDefinition for a Custom Page Type Field's Values

I want to populate a dropdown in my webpart from a custom page type field's values.
so for e.g I have a custom pagetype my.pagetype which has a field called myfield and has value like 1,2,3. How Do I get these 1,2,3 values ?
How do I access through SQL or macro so far I have reached till here and this code is giving me a long XML Schema string which has all fields definition and values of the custom page type.
CMSContext.Current.GlobalObjects.Classes["my.pagetype"].ClassFormDefinition
How do I get around?
Are you populating the drop down list in that Page Type manually? (e.g. 1, 2, 3)
If you want to reuse the same list of value in multiple places, it's better for you to create a custom table to store those value (e.g. customtable_myListX). Then for the drop down list, you can use the SQL option (SELECT Value, Display FROM customtable_myListX).

How to hide record in Form grid based on display method value?

I have a simple Form, in my DataSource I created a classic displayMethod (named calculateAmount) and use this metodod to show the value in Form's grid.
So It's possible to show only record having a specific value from calculateAmount , for example I want to show only record having calculateAmount() > 0 , other record with calculated calculateAmount() < 0 not show.
So if I can't mix Query and displayMethod, possibly where I can insert the condition (for example active executeQuery etc) ?
Thanks in advice.
Consider the following sequence:
Execute query is called and the AOT query is translated into SQL query
Results are fetched from SQL server after executeQuery()
Display method is called for each record and then the values are shown on grid
So you cannot add query range on execute query based on display method value.
One thing you can do:
Duplicate your datasource table and set its Table Type property to TempDB
In executeQuery method write the logic to fill this new created table
Here you can add this condition like this:
if ([your data source].calculateAmount() > 0)
{
// do not add the record in temp table
}
else
{
// add the record in temp table
}
Set your temp table as the datasource to your grid.
Hope this helps!!

How to access a cell value when the column has been defined with ag-grid expression/value getters?

If the ag-grid column definition has been defined with a value getter or if an expression has been defined for a cell the value gets displayed fine on the grid. However I was not able to find a way to access a value in a given cell if the cell is using cell expression/value getters. Was trying to access the data through api.forEachLeafNode, but it seems even the in memory model does not have this data. The only way I found was to export the data as CSV and then parse it using getDataAsCsv(params).
Is exporting the data the only way to access value of a column in a grid with a value getter?
Why does the In Memory model not have this data to access?
valueGetter is used during the rendering stage, it only computes when needed to render the cell. if the cell is never rendered (eg row is below what is currently visible) then the valueGetter is never executed. the result is never stored in the model, it is only passed to the cellRenderer.
so what you need to do to get the result of valueGetter is use api.getValue(colKey,rowNode)
colKey is the id of your column. this can be the column itself (if you got the column from the grid column api) or the column id. the column id is what you will probably want to use. the column id is assigned to the column in the following order 1) the colDef.colId if exists 2) the colDef.field if exists 3) generated if both colId and field are missing. so if you are using a valueGetter, you are probably not providing a field, so just provide a colId.
rowNode is the row in question. this is what you get when you use api.forEachLeafNode.
the api.getValue() method is pretty recent, i know it's in version 7 - so if missing just make sure you are v7 or above.

SAPUI5 table: get none-displayed values of selected row?

I have a SAPUI5 (OpenUI5) application with a table. This table is bound to a (JSON) model and display the name of the entity and some other attribute - but not the technical key.
The user should have the opportunity to select multiple lines in the table and the application should then be able to get the technical keys of the selected lines (probably using the underlying model).
How would I do such a thing?
Thanks in advance!
The rowSelectionChange event has a rowContext attribute. A better approach would be
rowSelectionChange: function(oEvent) {
console.log(oEvent.getParameters().rowContext.getProperty("your_key"));
}
to obtain the value of your key (or any field in the selected row by adapting the getProperty value accordingly)
when you will select a row in a table, there is a event called "rowSelectionChange". Use this event and getSelectedInedx of row.
Using the index value loop over your json and get values selected row.

How do I ignore the created column on a Zend_DB table save?

how would I ignore having Zend_DB save() from trying to fill out a created column? I do not need that column for a certain model.
Don't send the data. save() is part of the Zend_Db_Table_Row api and is designed to be somewhat intelligent in the way it saves data to a row. It will perform an insert or an update of a row depending on what is required.
save() will also only update the columns that it has data for. If you don't send new data for your created column save() won't overwrite the data.
When ever it is possible I let the database I'm using create and update the columns for created and updated. That way I have the information available to query if I need it but I don't have to do something with PHP that My database can do better.
Check out http://framework.zend.com/manual/1.12/en/zend.db.table.html Section "Advanced usage".
For more specific and optimized requests, you may wish to limit the
number of columns returned in a row or rowset. This can be achieved by
passing a FROM clause to the select object. The first argument in the
FROM clause is identical to that of a Zend_Db_Select object with the
addition of being able to pass an instance of Zend_Db_Table_Abstract
and have it automatically determine the table name.
Important
The rowset contains rows that are still 'valid' - they simply contain
a subset of the columns of a table. If a save() method is called on a
partial row then only the fields available will be modified.
So, if you called an update() I think it would be as simple as unsetting the value for the column you don't want to touch. Of course database constraints will need to be honored - i.e. column should allow nulls.