How to sort data in store depending on conditions in senchatouch - sencha-touch

I insert data in store depending on conditions
Ext.getStore('storename').add({
PlanUnplanned:data[i].PlanUnplanned==null?"Unplanned":Planned,
});
Now I am using dataview / dataitem to display the records. How do I sort the store such that the planned records are displayed first and the unplanned records are displayed next in sequence

You can change your store sorting like this:
Ext.getStore('storename').sort('PlanUnplanned', 'ASC');
You also can define that direct on your store
Source: http://docs.sencha.com/touch/2.3.0/#!/api/Ext.data.Store

Related

React-Admin filters that relate to the current results

We're really enjoying using the capabilities offered by React-Admin.
We're using <ReferenceArrayInput> to allow filtering of a <List> by Country. The drop-down contains all countries in the database.
But, we'd like it to just contain the countries that relate to the current set of filtered records.
So, in the context of the React-Admin demo, if we've filtered for Returned, then the Customer drop-down would only contain customers who have returned items (see below). This would make a real-difference in finding the records of interest.
Our current plan is to (somehow) handle this in our <DataProvider>. But, is there are more ReactAdmin friendly way of doing this?
So you want to build dependent filters, which is not a native feature of react-admin - and a complex beast to tame.
First, doing so in the dataProvider will not work, because you'll only have the data of the first page of results. A record in a following page may have another value for your array input.
You could implement that logic in a custom Input component instead. This component can wrap the original <ReferenceArrayInput> and read the current ListContext to get the current data and filter value (https://marmelab.com/react-admin/useListContext.html), then alter the array of possible values using the filter prop (https://marmelab.com/react-admin/ReferenceArrayInput.html#filter).

Insert to certain row in sqlflite

I am attempting to make a database that stores user information on the device. I am using flutter combined with sqlflite. I want to always store the data of the current user in row one of the SQL database. Is there anyway to do that with the .insert method?
int id = await db.insert(
'user',
user.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace,
);
This is the code I am using for inserting, but when the user changes the screen name or email, it will put the user now into the second row.
After a long period of research, I came to discover that the issue was not in my SQL code, it was instead in my use of the code. The object was returning a list of all objects and I was thinking it was returning one object.

SOLR: populate with data from children

I have Products in my SOLR index. I need to create calculated fields for each product. These fields are based on product's children.
Is it possible to create such calculated fields?
For example, I have a Product with id 1, I need to add all the Detail entities, which have "parentId" field value 1. Here is a brief schema: https://www.screencast.com/t/EkNG8NpFp.
I need to have values "v1", "v3" from the example above.
not sure what you exactly mean by "create such calculated fields"...
if you mean if you can query for Products and then for example get the average of field 'value'. Yes you can do stuff like that, look at json facets and how you can use children docs.
if you mean how you can add some new field to your Product doc, based on the values of the children docs, then you can probably do it with Streaming Expressions. You need to use the current collection as a source, and compute the new fields, and finally add the new docs (including the new field) into a new collection

Few questions about Grails' createCriteria

I read about createCriteria, and kind of interested on how these works, and its usability in providing values for dropdown box.
So say, i have a table in the database, Resource table, where i have defined the table in the domain class called Resource.groovy. Resource table has a total of 10 columns, where 5 of it are
Material Id
Material description
Resource
Resource Id
Product Code
So using the createCriteria, and i can use just like a query to return the items that i want to
def resList = Resource.createCriteria().list {
and {
eq('resource', resourceInstance)
ne('materialId', '-')
}
}
Where in the above, i want to get the data that matches the resource = resourceInstance, and none of the materialId is equal to '-'.
I want to use the returned data from createCriteria above on my form, where i want to use some of the column on my select dropdown. Below is the code i used for my select dropdown.
<g:select id="resourceId" name="resourceId"
from="${resList}"
disabled="${actionName != 'show' ? false : true}" />
How do i make it so that in a dropdown, it only shows the values taken from column Product Code? I believe the list created using createCriteria returns all 10 columns based on the createCriteria's specification. But i only want to use the Product Column values on my dropdown.
How do i customize the data if in one of the select dropdown in my form, i wanted to show the values as "Resource Id - Resource Description"? The values are combination of more than 1 columns for one select dropdown but i don't know how to combine both in a single select dropdown.
I read that hql and GORM query are better ways of fetching data from table than using createCriteria. Is this true?
Thanks
First of all refer to the document for using select in Grails. To answer all questions:
Yes, the list to select from in the dropdown can be customized. In this case it should be something like from="${resList*.productCode}"
Yes, this can be customized as well with something like
from="${resList.collect { \"${it.resourceId} - ${it.resourceDesc}\" } }"
It depends. If there are associations involved in a domain then using Criteria will lead to eager fetches which might not be required. But with HQL one gets the flexibility of tailoring the query as needed. With latest version of Grails those boundries are minimized a lot. Usage of DetachedCriteria, where queries etc are recommended whereever possible. So it is kind of mixing and matching to the scenario under consideration.

Duplicate a record and its references in web2py

In my web2py application I have a requirement to duplicate a record and all its references.
For example
one user has a product (sponserid is the user). and this product has so many features stored in other tables (reference to product id).
And my requirement is if an another user is copying this product, the a new record will generate in the product table with new productid and new sponserid. And all the reference table records will also duplicate with the new product id. Effectively a duplicate entry is creating in all the tables only change is product id and sponserid.
The product table fields will change. So I have to write a dynamic query.
If I can write a code like below
product = db(db.tbl_product.id==productid).select(db.tbl_product.ALL).first()
newproduct = db.tbl_product.insert(sponserid=newsponserid)
for field,value in product.iteritems():
if field!='sponserid':
db(db.tbl_product.id==newproduct).update(field=value)
But I cannot refer a field name like this in the update function.
Also I would like to know if there is any other better logic to achieve this requirement.
I would greatly appreciate any suggestions.
For the specific problem of using the .update() method when the field name is stored in a variable, you can do:
db(db.tbl_product.id==newproduct).update(**{field: value})
But an easier approach altogether would be something like this:
product = db(db.tbl_product.id==productid).select(db.tbl_product.ALL).first()
product.update(sponserid=newsponserid)
db.tbl_product.insert(**db.tbl_product._filter_fields(product))
The .update() method applied to the Row object updates only the Row object, not the original record in the db. The ._filter_fields() method of the table takes a record (Row, Storage, or plain dict) and returns a dict including only the fields that belong to the table (it also filters out the id field, which the db will auto-generate).