I want to implement the data virtualization, but I dont know where to put my real collection of data in this example:
http://blogs.msdn.com/b/ptorr/archive/2010/08/16/virtualizing-data-in-windows-phone-7-silverlight-applications.aspx
Let us say your collection is List where Person is a Custom Class you have defined.
You should read a small subset of data from either a Service or Isolated Storage and set it as below.
In the VirtualizedDataSource.cs file update the getter of "this" property as under
if (itemToReturn == null)
{
if (simpleCache.Count >= CACHE_SIZE)
{
DataItem oldItem = simpleCache.Dequeue();
Debug.WriteLine("Purging\t" + oldItem.Index + "\t" + oldItem.Text);
oldItem.Text = "DEAD ITEM";
}
itemToReturn = **new Person();**
text += "\t" + itemToReturn.Text;
simpleCache.Enqueue(itemToReturn);
}
Hope this helps.
Related
I want to change the value of a variable called "value" which represent the shown value in the screen according to my database, here is my code
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val mViewModel = ViewModelProvider(this).get(ExpenseCalculatorViewModel::class.java)
binding.categoryName.text = args.category
val viewModel = ViewModelProvider(this).get(CategoriesViewModel::class.java)
when (binding.categoryName.text) {
getString(R.string.restaurant) -> {
viewModel.readRestaurantData.observe(viewLifecycleOwner, {
var value = 0
for (i in it.indices) {
value += it[i].restaurant
}
binding.totalNumber.text = value.toString()
})
}
please I need a useful answer and thanks for your patience
You need to perform an update query. Using ROOM for your SQLITE, you create the update query on your DAO class, you can call RestaurantDao. Allocate all your queries there such as update, delete, insert, etc.
Example: (modify the names of the table and variables according to your table structure.
#Query("UPDATE my_restaurant_table SET value=:value " +
"WHERE id=:id"
) public abstract void updateRestaurant(
long id,
String value
);
I'm trying to create an XTemplate, and one of my dataIndexes has a period... so my data looks something like this:
{
"one": 1,
"two.one": 21,
"two.two": 22
}
Now, when I'm creating the template, I can't do something like {two.one} because that thinks two is the beginning of an object, and then I'm accessing its key one. I've tried doing something like {'two.one'}, but this also doesn't work, and I've tracked it down to the culprit in Ext.XTemplateCompiler.parseTag. This code is what breaks it:
// compound Javascript property name (e.g., "foo.bar")
else if (isNaN(name) && name.indexOf('-') == -1 && name.indexOf('.') != -1) {
v = "values." + name;
}
// number or a '-' in it or a single word (maybe a keyword): use array notation
// (http://jsperf.com/string-property-access/4)
else {
v = "values['" + name + "']";
}
So with my two.one string, I get into that else if, but what I really want is the else that follows right after it. Unfortunately, it doesn't seem like I can override this in an easy way... does anybody have any thoughts? I'm using Ext JS 4.2.1.
Thanks to skirtle over on the Sencha Forums, I was able to solve it:
Instead of using {two.one} or {'two.one'}, it should be {[values['two.one']]}. Using values directly was the ticket.
What is the best way for searching the fields AT THE MOMENT in database with angularjs?
I have a JSON inside a field of database...
I want, when a user fill a text box (TextBox1), in exact time, it search at the moment inside my database. if that entire text was equal with any field of a table, fill another textbox(TextBox2) automatically.
With below code, i can fill it. and it works properly. but i thinks its not logical. Because it reads all of my data in mentioned Table first
$scope.showFullName = function(){
$scope.Fullname="";
if($scope.MembersNationalCode.length == 10) {
for (var i = 0; i < $scope.NaturalMembers.length; i++) {
if ($scope.NaturalMembers[i].NationalNumber == $scope.MembersNationalCode) {
$scope.Fullname = $scope.NaturalMembers[i].Name + " " + $scope.NaturalMembers[i].Family;
}
}
}
};
I'm mentioning again. It works properly. But i'm looking for best way. And this question is a sample.
Thanks.
I use ExtJs 3.3.1 because many extensions don't work under 4.xx
One of these extensions is LiveGrid.
I can't try but i suppose a simmilar thing happens with a 4.x buffered grid.
When i do a report of the lines visible in the grid only the buffered lines are returned, i reposition the current record but the loading of the rest of the records only happens after the reporting finishes. How can i get all the records ?
In an button handler i call toReport(grid).
toReport = function(grid){
var store = grid.getStore();
var view = grid.getView();
store.each(function(record) {
Ext.defer(function(){
index = readRow(store, record);
if (index % 10 == 0){
view.focusRow(index);
}
}, 500, this);
});
console.log(output)
}
readRow = function(store, record){
output = "";
for (var xlCol=1;xlCol<record.fields.length+1;xlCol++){
var veld = store.fields.itemAt(xlCol-1).name;
waarde = record.get(veld);
if (realTypeOf(waarde)==="date"){
output += waarde.format("d-m-Y");
}else{
output += record.get(veld);
}
}
console.log(store.indexOf(record)+ " " + output);
return store.indexOf(record);
}
The grid needs to manipulate its store filters, sorters, paging, etc., in order to obtain the records it want to display. The store itself only keeps in memory the subset of records that matches its filters, etc. That is the way stores are designed in Ext: they are intended to be bounded to one and only one view.
I think in your case, the simplest solution is to create another store with a similar configuration, and use its load method with params such that you get all the records.
If you're reticent to fire multiple requests for retrieving essentially the same data, have a look at Ext.data.Proxy. Unlike stores, proxies are not bound to a specific view or task and can be shared between multiple store instances. So in theory, you can create a proxy that requests all the records from the server at once, and then feeds a subset of them to multiple stores. For that you'll have to implement the doRequest method of the proxy (or most probably overrides the one of the proxy you're already using).
I did find a solution by using recursion.
Like this the view kan keep up with the enumeration.
Ext.toExcel = function(grid){
var store = grid.getStore();
var view = grid.getView();
readRow(store, view, 0);
}
readRow = function(store, view, index){
output = "";
record = store.getAt(index);
for (var xlCol=1;xlCol<record.fields.length+1;xlCol++){
var veld = store.fields.itemAt(xlCol-1).name;
waarde = record.get(veld);
if (realTypeOf(waarde)==="date"){
output += waarde.format("d-m-Y");
}else{
output += record.get(veld);
}
}
//console.log(index+ " " + output);
if (index % 50 == 0){view.focusRow(index);}
Ext.defer(function(){
if (index < store.totalLength){
readRow(store, view, index+1);
}
}, 100, this);
}
I have the following code in ViewModel, I would like to remove a record from an entity but it doesn't work. Can someone please shed some light...?
Usertable users = new Usertable();
users.User_ID = Entity.User_ID;
users.user_role = "Admin";
Entity.CompanyRoles.Remove(users);
Instead if I replace the Remove with Add, it will add one record to the entity.
Only Remove is a concern to me.
First you need to fetch the entity you are about to remove, then remove it, then save your changes to the datacontext:
var userToRemove = Entity.CompanyRoles.Single(cr => cr.user_role == "Admin");
Entity.CompanyRoles.DeleteObject(userToRemove);
Entity.SaveChanges();
Objects are compared by reference, not values, so unless Entity.CompanyRoles contains the exact reference in memory as the object you're trying to remove, it won't find the object in the collection and remove it.
There are two ways to fix it.
The best way is to get a reference to the object in the collection like Paul suggests
var userToRemove = Entity.CompanyRoles.Single(cr =>
cr.user_role == "Admin" && cr.User_ID = Entity.User_ID);
Entity.CompanyRoles.Remove(userToRemove);
Or another method that works is to overwrite the .Equals() of the object to consider them equal if the data is the same, regardless of the memory reference. I would not usually recommend this except in special cases since it affects any operation that compares one copy of this object to another using .Equals()
public override bool Equals(object obj)
{
if (obj == null || !(obj == MyClass))
return false;
var obj2 = obj as MyClass;
return obj2.user_role == this.user_role && obj2.User_ID == this.User_ID;
}