Git Product home page Git Product logo

Comments (11)

akgulebubekir avatar akgulebubekir commented on May 29, 2024

Hi ,

  1. Which platform are you using ?
  2. Is it possible to provide us a sample code?

from xamarin.forms.datagrid.

MichaelSafro avatar MichaelSafro commented on May 29, 2024

from xamarin.forms.datagrid.

MichaelSafro avatar MichaelSafro commented on May 29, 2024

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.

MichaelSafro avatar MichaelSafro commented on May 29, 2024

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.

MichaelSafro avatar MichaelSafro commented on May 29, 2024

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.

prom3theu5 avatar prom3theu5 commented on May 29, 2024

Same issue here with ObservableCollection

from xamarin.forms.datagrid.

akgulebubekir avatar akgulebubekir commented on May 29, 2024

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.

MichaelSafro avatar MichaelSafro commented on May 29, 2024

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.

MichaelSafro avatar MichaelSafro commented on May 29, 2024

Thanks a lot Ebubekir! This worked.

from xamarin.forms.datagrid.

akgulebubekir avatar akgulebubekir commented on May 29, 2024

from xamarin.forms.datagrid.

assemhakmeh avatar assemhakmeh commented on May 29, 2024

from xamarin.forms.datagrid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.