Comments (11)
Hi ,
- Which platform are you using ?
- Is it possible to provide us a sample code?
from xamarin.forms.datagrid.
from xamarin.forms.datagrid.
XAML View
<local:TransactionsViewBase
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XNameSpace.TransactionsView"
xmlns:local="clr-namespace:XNameSpace"
Title="Transactions"
xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid"
>
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="0" Padding="10" Grid.ColumnSpan="2">
<dg:DataGrid ItemsSource="{Binding Transactions}"
RowHeight="50"
HeaderHeight="30"
BorderColor="#CCCCCC"
HeaderBackground="#E0E6F8"
SelectionEnabled="True"
SelectedItem="{Binding SelectedTransaction}" x:Name="DataGrid"
IsSortable="True"
SortedColumnIndex="2"
>
<dg:DataGrid.HeaderFontSize>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Tablet>15</OnIdiom.Tablet>
<OnIdiom.Phone>13</OnIdiom.Phone>
</OnIdiom>
</dg:DataGrid.HeaderFontSize>
<dg:DataGrid.Columns>
<dg:DataGridColumn Title="TransactionType" PropertyName="transaction_type" Width="0.95*"/>
</dg:DataGrid.Columns>
</dg:DataGrid>
</StackLayout>
<Button Text="Remove" Grid.Row="1" Grid.Column="0" Command="{Binding Remove}"/>
</Grid>
</ContentPage.Content>
</local:TransactionsViewBase>`
from xamarin.forms.datagrid.
ViewModel
using Autofac;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace XNameSpace
{
public class TransactionsViewModel:BaseViewModel, INotifyPropertyChanged, IViewModel
{
private DatabaseService database;
private Transaction selectedTransaction;
private bool isRefreshing;
public TransactionsViewModel()
{
database = new DatabaseService();
FillTransactions();
this.Remove = new Command(async () =>
{
var answer = await Application.Current.MainPage.DisplayAlert("Attention", "Confirm changes?", "Yes", "No");
if (selectedTransaction != null)
{
Transactions.Remove(selectedTransaction);
}
});
}
public void FillTransactions()
{
if (Transactions == null)
{
Task.Run(async () =>
{
Transactions = new ObservableCollection<Transaction>(await database.Get<Transaction>());
foreach (var _Transaction in Transactions)
{
await database.Delete(_Transaction);
}
await AddMockedTransactions();
Transactions = new ObservableCollection<Transaction>(await database.Get<Transaction>());
}
).Wait();
}
}
private ObservableCollection<Transaction> Transactions;
public ObservableCollection<Transaction> Transactions
{
get{
return Transactions;
}
set
{
Transactions = value;
OnPropertyChanged();
}
}
private async Task AddMockedTransactions()
{
await database.Add(
new Transaction
{
transaction_type = "C",
}
);
await database.Add(new Transaction
{
transaction_type = "R",
}
);
await database.Add(new Transaction
{
//need a decorator
transaction_type = "I",
}
);
await database.Add(new Transaction
{
//need a decorator
transaction_type = "S",
}
);
}
public ICommand Remove { protected set; get; }
public Transaction SelectedTransaction
{
get { return selectedTransaction; }
set
{
selectedTransaction = value;
System.Diagnostics.Debug.WriteLine("Transaction Type Selected : " + value.transaction_type);
}
}
}
}
}
`
from xamarin.forms.datagrid.
Let me know if this works for you. We did this after the example provided by you guys, but changed the collection from List to ObservableCollection to ensure that the grid updates when needed. It does now, but sadly does not display when the page loads. With List it is reverse situation, does not update, but works when first loaded. Model implements INotifyPropertyChanged for few properties, otherwise it is just a standard entity class.
from xamarin.forms.datagrid.
Same issue here with ObservableCollection
from xamarin.forms.datagrid.
Hi ,
Sorry for late response. I've been quite busy recently.
It seems we resolved that issue in #28 and published a nuget package with 1.8.5-pre1 version.
Please confirm if it resolve your issue, if so please close this thread.
from xamarin.forms.datagrid.
I will be doing this in a day or 2. Thanks a lot for taking care of this, this was a quick response!
from xamarin.forms.datagrid.
Thanks a lot Ebubekir! This worked.
from xamarin.forms.datagrid.
- thanks @assemhakmeh for the implementation (#28).
from xamarin.forms.datagrid.
from xamarin.forms.datagrid.
Related Issues (20)
- Xamarin forms Datagrid retrieve data
- It cannot center long texts HOT 1
- Rows show but without text ONLY in production (iOS, Android) HOT 1
- froze first column HOT 2
- Having a decimal Input Column HOT 1
- Formatting date/Number DataGridColumn
- Support for BindingList? HOT 1
- How do you clear the list ? HOT 2
- Swipe View HOT 1
- grid title in IOS is not working HOT 1
- DataGrid's ItemsSoure not showing on first load. I have to sort the grid by tapping on header to show the data. HOT 1
- Vertical grid lines slightly misaligned on iOS HOT 1
- How to create DataGridColumn consisting DataTemplate progamatically? HOT 1
- MAUI Support HOT 3
- Multi Select problem HOT 2
- Selection does not work with the new nuget HOT 2
- How insert a dg:DataGrid in Grid
- Rows not visible when DataGrid is inside a StackLayout HOT 1
- Hide the column in the DataGridColumn HOT 1
- Any Support for MAUI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xamarin.forms.datagrid.