Blazorise DataGrid syntax to create and execute Commands with parameters on a Button? - datagrid

How does one save data (multiple rows) in a Blazorise DataGrid?
Is there an example of the code including the C# functions to update a database?

Blazorise uses automatic CRUD - but you need to call something like this in code:
async Task OnSaveClicked()
{
// check validation if needed
if (Items != null)
{
await _context.SaveChangesAsync();
}
to update the database. It only needs to be done once for the whole grid.
I suggest using EditMode="DataGridEditMode.Inline for inline editing.
If an error occurs it will show a Reload at the bottom - check your browser developer tools to see what has caused the error.

Related

Using Anko SQLLite, what is the best way to check if a database exists?

I'm working on an Android app using Kotlin and as part of the startup process, I would like to determine whether or not a SQL Lite database already exists (meaning the user is not a new user)
I've so far been unable to determine what is the best way to do this using the ManagedSQLiteOpenHelper helper infrastructure from the Anko SQLLite helpers.
database.use {
// what should go in here???
}
I don't necessarily want to query a non existent table and thus throw an exception and use that as a form of logic control, is there a better way?
Answered my own question.
This works
this.query("sqlite_master", arrayOf("name"), "name='userInfo' AND type='table'", null,null,null, null,null).count
You may use this:
db.use{
select("youtTableName").whereSimple("fieldId = ?",id).exec {
//your code here
}
}

How to display error on the client when using ASP.NET MVC AJAX

I am using ASP.NET MVC AJAX with the #AJAX.ActionLink helper to implement item deletion from a grid. When the request is executed it returns the grid without the deleted item and the AJAX helpers replace the grid. This works just fine but the problem is what to do if the item cannot be deleted (in my case due to foreign key constraints). How can I report the error to the client and display appropriate message. I don't want to use the OnFailure function blindly because I don't want to show the same error message for all errors. Ideally there will be a way to send specific error from the action and inspect the error in the JavaScript OnFailure function but I can't seem to find it.
Of course I can downgrade to returning JSON, manually executing AJAX calls and replacing UI elements but I don't really feel like it. I'd rather do something dirty like render a hidden input with the error information and check for it on the client but I don't want to do that either if there is better way.
You can return status code and error message from the controller and pass it to the ajax OnFailure function
return new HttpStatusCodeResult(HttpStatusCode.Conflict, "The entity is currently used");
as shown here: ASP.NET MVC AJAX onError handling
and in the client side JS:
function deleteFailure(responce) {
var statusCode = responce.status;
var responceText = responce.statusText;
if(statusCode == 409){
//do something specific for specific errors
}
alert(responceText);
}

Two-way data-binding with ng-grid?

How do I get two-way data-binding with ng-grid?
I am working from their pagination example, and have figured out how factory and broadcast work; and have thus successfully loaded new versions of my data into the relevant controller.
How do I enable two way data-binding on the myData variable?
I have tried these two separate things:
$scope.gridOptions.data = <injected object>;
$scope.myData = <injected object>;
What's the trick to enabling two-way data-binding on the myData object?
It should work by default. I took the example plunker from ng-grid site and modified the content and it did automatic update.
See here
http://plnkr.co/edit/8St4ya?p=preview
See this code
$scope.changeData=function(){
$scope.myData[0].name="NewName";
};
In case you grid is not getting updated on change in the binded data, the reason could be
The object bound is not array.
You are getting data in async manner (http call). Try to call $scope.$apply() after you get the data from server and update the collection

Writing changes from editable datagrid back to local data store - Adobe Air/Flex

I am using Adobe Air to get data from SalesForce, and present it in a datagrid.
I am using a query to get the data, and then put it into an arraycollection that is bound to the datagrid, this works correctly and the data is displayed.
I have made the datagrid editable, and I am able to change the values in the datagrid, but I cannot find how to save the changes to the local database.
I am using the following code:-
protected function VisitReportGrid_changeHandler(event:ListEvent):void{
app.wrapper.save(VisitReportGridProvider)
}
But this has the following error when I try and compile it:-
1067: Implicit coercion of a value of type mx.collections:ArrayCollection to an unrelated type mx.data:IManaged.
Obviously I am doing this wrong, but I cannot find the correct syntax.
Thanks in advance for your help
Roy
This code is not enough to understand where actually is the problem
Need to know what is VisitReportGridProvider, what is wrapper.save() method.
**after comment:
F3DesktopWrapper.save():
public function save(item:IManaged):void
Saves the specified Managed object to the local database. You must make an explicit call to syncWithServer() to update the data on the salesforce server. However, do not call syncWithServer() too often (batch your save calls) as this may use up your alloted API usage. If the item is in conflict, the conflict will be resolved.
Parameters:
item:IManaged — The managed object to create or update.
you're passing parameter with type ArrayCollection which doesn't implement IManaged interface.
You need to pass the item in the ArrayCollection that was changed to the save function. Like:
acc.fieldCollection.updateObject(new AsyncResponder(function(o:Object, t:Object):void {
app.wrapper.save(o as Account);
}, function(e:Object):void {
}));

list box control in asp.net

Hello friends I have a list box control in my asp.net project.
I want to know how to get selected index to set currently updated item in database.
Please help me with this. Do i need to perform some data base operation to find the key for currently updated data and then i'll have to set it or there exist some property to deal with this? thanks in adavance
One thing to watch out for, which I have come accross more than once is that if you call your CompanyListBox() method in your Page_Load method, you will lose the selected index unless it is only called on the first page load. To make sure of this, place your call to CompanyListBox() within the following block:
if(!Page.IsPostBack)
{
CompanyListBox();
}
You can access the selected index in your postback by using the following code:
var id = (Int32)listCompany.SelectedItem.Value
Then it is up to you to use that in your data access to update the record in the database. Looks to me that you are using some kind of framework or manager class for your database access. The companyManager should have methods for saving your updated item to the database. Good luck.

Resources