This is a migrated thread and some comments may be shown as answers.

Get Current rows from RadGrid

1 Answer 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tamara
Top achievements
Rank 1
Tamara asked on 01 Apr 2020, 10:05 PM

Is there any way to get current rows  from RadGrid on Server side, because I want to call some method end set some of the fields only for currently showed rows. I'm using OnNeedDataSource and i have grouping and sorting in my RadGrid. 

For better understanding here is example:

I have 1000 elements in database and i want my method to apply only on items that i'm showing (10/20/50) one current page of paggination. 

<div class="demo-container no-bg">
                <telerik:RadGrid runat="server"
                    ID="OrdiniDashboard_Grid"
                    OnNeedDataSource="OnNeedDataSource_OrdiniDashboard"
                    RenderMode="Lightweight"
                    PageSize="10"
                    AllowSorting="True"
                    AllowMultiRowSelection="True"
                    AllowPaging="True"
                    ShowGroupPanel="True"
                    AutoGenerateColumns="False"
                    OnPreRender="GridOrdDashboard_PreRender"
                    OnItemCreated = "OnItemCreated">
                    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="True" Position="Bottom"></PagerStyle>
                    <MasterTableView
                        Width="100%"
                        GroupLoadMode="Client"
                        ShowGroupFooter="true"
                        ClientDataKeyNames="IdOrder, IdCliente,TipologiaCliente,RagSoc,NomeU,CognomeU,Confirm,PriorityId,PriorityCompleteName,FlagPagamento,StatoPagamento, OrdineEsportato, OrdineEsportatoName, totaleImporto,totaleValue">
                        <GroupByExpressions>
                            <telerik:GridGroupByExpression>
                                <SelectFields>
                                    <telerik:GridGroupByField
                                        FieldAlias="DataScadenza"
                                        FieldName="DataScadenza"
                                        HeaderText="<%$ Resources: Doc_Labels, dataScadenza %>"
                                        FormatString="{0:dd/MM/yyyy}"
                                        HeaderValueSeparator="from date: "></telerik:GridGroupByField>
                                </SelectFields>
                                <GroupByFields>
                                    <telerik:GridGroupByField
                                        FieldName="DataScadenza"></telerik:GridGroupByField>
                                </GroupByFields>
                            </telerik:GridGroupByExpression>
                            <telerik:GridGroupByExpression>
                                <SelectFields>
                                    <telerik:GridGroupByField
                                        FieldAlias="StatoOrdineValue"
                                        FieldName="StatoOrdineValue"
                                        HeaderText="Stato"></telerik:GridGroupByField>
                                </SelectFields>
                                <GroupByFields>
                                    <telerik:GridGroupByField
                                        FieldName="StatoOrdineValue"></telerik:GridGroupByField>
                                </GroupByFields>
                            </telerik:GridGroupByExpression>
                        </GroupByExpressions>

                        <Columns>

                        <telerik:GridBoundColumn
                                AutoPostBackOnFilter="false"
                                DataField="IdOrder"
                                DataType="System.Int32"
                                UniqueName="IdOrder"
                                Display="false"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn
                                AutoPostBackOnFilter="false"
                                DataField="IdCliente"
                                DataType="System.Int32"
                                UniqueName="IdCliente"
                                Display="false"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn
                                AutoPostBackOnFilter="false"
                                SortExpression="NumeroOrdine"
                                Groupable="false"
                                HeaderText=" <%$ Resources: Doc_Labels, numero %>"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                DataField="NumeroOrdine"
                                Display="true"
                                Aggregate="Count"
                                FooterAggregateFormatString="Ordini totali: {0}"
                                UniqueName="NumeroOrdine">
                            </telerik:GridBoundColumn> 

                            <telerik:GridBoundColumn AutoPostBackOnFilter="false"
                                SortExpression="JobName"
                                Groupable="false"
                                DataField="JobName"
                                Display="true"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText=" <%$ Resources: Doc_Labels, jobName %>">
                            </telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn
                                AutoPostBackOnFilter="false"
                                SortExpression="Cliente"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                UniqueName="Cliente"
                                DataField="Cliente"
                                GroupByExpression="Cliente Group By Cliente"
                                Groupable="true"
                                HeaderText=" <%$ Resources: Doc_Labels, cliente %>">
                                <ItemTemplate>
                                    <a href="../../../Views/settings/Clienti/Gestione_Cliente.aspx?idCliente="></a>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

                            <telerik:GridBoundColumn
                                UniqueName="DataOrdine"
                                AutoPostBackOnFilter="false"
                                SortExpression="DataOrdine"
                                HeaderText=" <%$ Resources: Doc_Labels, dataEmissione %>"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderButtonType="TextButton"
                                DataField="DataOrdine"
                                GroupByExpression="DataOrdine Group By DataOrdine"
                                Groupable="true"
                                DataFormatString="{0:dd/MM/yyyy}"
                                Display="true">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn
                                AutoPostBackOnFilter="false"
                                SortExpression="DataScadenza"
                                HeaderText=" <%$ Resources: Doc_Labels, dataScadenza %>"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderButtonType="TextButton"
                                DataField="DataScadenza"
                                DataFormatString="{0:dd/MM/yyyy}"
                                Display="true">
                            </telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn
                                AutoPostBackOnFilter="false"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                UniqueName="Confirm"
                                SortExpression="StatoOrdineValue"
                                HeaderButtonType="TextButton"
                                GroupByExpression="StatoOrdineValue Group By StatoOrdineValue"
                                HeaderText=" <%$ Resources: Doc_Labels, stato %>"
                                DataField="StatoOrdineValue"
                                DataType="System.String">
                                <ItemTemplate>
                                    <div></div>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

                            <telerik:GridTemplateColumn
                                UniqueName="Priority"
                                HeaderText="Priority"
                                SortExpression="PriorityCompleteName"
                                DataType="System.String"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                DataField="PriorityCompleteName"
                                GroupByExpression="PriorityCompleteName Group By PriorityCompleteName">
                                <ItemTemplate>
                                    <span class="label label-sm circle popovers infoPopOver"
                                        style="color: white; background-color: rgb(132, 151, 152);"
                                        data-placement="top"
                                        data-trigger="hover"></span>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

                            <telerik:GridBoundColumn
                                UniqueName="StatoDocumentoFattura"
                                DataField="StatoDocumentoFattura"
                                SortExpression="StatoDocumentoFattura"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText=" <%$ Resources: Doc_Labels, gestioneStatoDocumento %>"
                                GroupByExpression="StatoDocumentoFattura Group By StatoDocumentoFattura">
                            </telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn
                                UniqueName="StatoPagamento"
                                SortExpression="StatoPagamento"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText="<%$ Resources:Doc_Labels, statoPagamento %>"
                                HeaderStyle-HorizontalAlign="Center"
                                GroupByExpression="StatoPagamento Group By StatoPagamento"
                                DataField="StatoPagamento">
                                <ItemTemplate>
                                    <i class="fa fa-euro popovers"
                                        data-placement="top"
                                        data-trigger="hover"
                                        style="width: 100%"></i>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

                            <telerik:GridBoundColumn
                                UniqueName="TipoPagamento"
                                DataField="TipoPagamento"
                                SortExpression="TipoPagamento"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText=" <%$ Resources: Doc_Labels, tipoPagamento %>"
                                GroupByExpression="TipoPagamento Group By TipoPagamento">
                            </telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn
                                UniqueName="OrdineEsportato"
                                DataField="OrdineEsportato"
                                SortExpression="OrdineEsportato"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText=" <%$ Resources: Doc_Labels, esportato %>"
                                GroupByExpression="OrdineEsportatoName Group By OrdineEsportatoName">
                                <ItemTemplate>
                                    <i class=" fa fa-check-circle  popovers infoPopOver"
                                        data-placement="top"
                                        data-trigger="hover"
                                        style="width: 2%"></i>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

                            <telerik:GridBoundColumn
                                UniqueName="DataEsportazioneOrdine"
                                DataField="DataEsportazioneOrdine"
                                SortExpression="DataEsportazioneOrdine"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText="Data Esportazione Ordine"
                                DataFormatString="{0:dd/MM/yyyy}"
                                GroupByExpression="DataEsportazioneOrdine Group By DataEsportazioneOrdine">
                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn
                                UniqueName="Autore"
                                DataField="Autore"
                                SortExpression="Autore"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                HeaderText=" <%$ Resources: Doc_Labels, autore %>"
                                GroupByExpression="Autore Group By Autore">
                            </telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn
                                AutoPostBackOnFilter="false"
                                DataType="System.Decimal"
                                UniqueName="totaleImporto"
                                Display="true"
                                Aggregate="Sum"
                                FooterAggregateFormatString="Imponibile: {0:C}"
                                HeaderText="<%$ Resources: Doc_Labels, imponibile %>"
                                DataField="totaleImporto"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                Groupable="false">
                            </telerik:GridTemplateColumn>

                            <telerik:GridTemplateColumn
                                AutoPostBackOnFilter="false"
                                DataType="System.Decimal"
                                UniqueName="totaleValue"
                                Display="true"
                                Aggregate="Sum"
                                FooterAggregateFormatString="Totali: {0:C}"
                                HeaderText="<%$ Resources: Doc_Labels, totali %>"
                                DataField="totaleValue"
                                HeaderStyle-HorizontalAlign="Center"
                                ItemStyle-VerticalAlign="Middle"
                                ItemStyle-HorizontalAlign="Center"
                                Groupable="false">
                                <ItemTemplate>
                                    <div>
                                    </div>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings
                        ReorderColumnsOnClient="True"
                        AllowDragToGroup="True"
                        AllowColumnsReorder="True">
                        <ClientEvents
                            OnGroupExpanded="OrdDashboard_OnGroupExpandedCollapse"
                            OnGroupCollapsed="OrdDashboard_OnGroupExpandedCollapse"
                            OnRowCreated="OnRowDataBoundOrdini"
                            OnCommand="OnCommadFunction"></ClientEvents>
                        <Selecting AllowRowSelect="True" />
                        <Resizing
                            AllowRowResize="False"
                            AllowColumnResize="False"
                            EnableRealTimeResize="False"
                            ResizeGridOnColumnResize="False"></Resizing>
                    </ClientSettings>
                    <GroupingSettings ShowUnGroupButton="true" RetainGroupFootersVisibility="false" />
                </telerik:RadGrid>
            </div>

 

        public ResultData GetOrdiniListForDashboard(string filterExpression)
        {
            var result = new ResultData();
            MyRigaPrev rigaPrev = new MyRigaPrev();
            DocNewReport_footer_ord_prev_Result my;
            DALDocumentale db = new DALDocumentale(0);          // Database
            try
            {
                //IQueryable<MyOrdDashboard> list = null;
                var list = (from ord in db.Ordini
                            where (ord.TipologiaDocumento == null || ord.TipologiaDocumento == "order" && ord.IdOrder > 0)
                            join prioritySetts in db.Priority on ord.PriorityId equals prioritySetts.Id
                            into priority
                            from p in priority.DefaultIfEmpty()
                            select new MyOrdDashboard
                            {
                                IdOrder = ord.IdOrder ?? 0,
                                IdCliente = ord.IdCliente ?? 0,
                                TipologiaCliente = ord.TipologiaCliente ?? 0,
                                RagSoc = ord.RagSoc ?? "",
                                NomeU = ord.NomeU ?? "",
                                CognomeU = ord.CognomeU ?? "",
                                PriorityId = ord.PriorityId ?? 0,
                                NumeroOrdine = ord.NumeroOrdine ?? "",
                                JobName = ord.JobName ?? "",
                                DataOrdine = ord.DataOrdine,
                                DataScadenza = ord.DataScadenza,
                                Confirm = ord.Confirm ?? 0,
                                //PriorityName = p != null && !string.IsNullOrEmpty(p.Name) ? p.Name[0] : 'N',
                                PriorityCompleteName = p.Name ?? "Nessuna",
                                //StatoOrdine = ord.Confirm ?? 0,                                                                 // State of ordine:
                                StatoOrdineValue = ord.Confirm == 1 ? "In Coda" :                                                                    // 1 -- InCoda
                                                  (ord.Confirm == 2 ? "In Lavorazione" :                                                             // 2 -- InLavorazione
                                                  (ord.Confirm == 3 ? "Evaso" : "Annullato")),                                                       // 3 -- Evaso
                                                                                                                                                     // 4 -- Annullato
                                Cliente = ord.TipologiaCliente == 5 || ord.TipologiaCliente == 6 ? ord.RagSoc : ord.NomeU + " " + ord.CognomeU,      // Type of client: 
                                                                                                                                                     // private: NomeU + CognomeU
                                                                                                                                                     // company: RagSoc
                                StatoDocumentoFattura = ord.StatoDocumentoFattura == "fatturatoParziale" ? Resources.Doc_Labels.fatturatoParziale :
                                                        (ord.StatoDocumentoFattura == "fatturato" ? Resources.Doc_Labels.fatturato :
                                                        (ord.StatoDocumentoFattura == "nonFatturabile" ? Resources.Doc_Labels.nonFatturabile :
                                                        (ord.StatoDocumentoFattura == "daFatturare" ? Resources.Doc_Labels.daFatturare :
                                                        (ord.StatoDocumentoFattura == "" || ord.StatoDocumentoFattura == null ? Resources.Doc_Labels.daFatturare : "")))),


                                StatoGatewayTransazione = ord.StatoGatewayTransazione ?? 0,
                                StatoPagamento = ord.StatoGatewayTransazione == 0 ? Resources.Doc_Labels.nonEseguito : Resources.Doc_Labels.eseguito,
                                FlagPagamento = ord.StatoGatewayTransazione ?? 0,
                                IdGateway = ord.IdGateway ?? 0,
                                TipoPagamento = ord.TipologiaPagamento ?? Resources.Doc_Labels.nessuno,
                                OrdineEsportato = ord.OrdineEsportato ?? false,
                                OrdineEsportatoName = ord.OrdineEsportato != null ? Resources.Doc_Labels.esportato : Resources.Doc_Labels.nonesportato,
                                DataEsportazioneOrdine = ord.DataEsportazioneOrdine,
                                Autore = ord.EmessoDa,
                                //totaleImporto = Convert.ToDecimal((rigaPrev.getTotali(Convert.ToInt32(ord.IdOrder), "ordine", "").Imponibile)),
                                //totaleValue = Convert.ToDecimal((rigaPrev.getTotali(Convert.ToInt32(ord.IdOrder), "ordine", "").Totale)),
                            });

                //IQueryable<MyOrdDashboard> ordini = null;

                //replace DateTime.Parse
                int countDate = Regex.Matches(filterExpression, "DateTime.Parse").Count;
                var listaDate = new object[countDate];

                if (countDate > 0)
                {
                    //for the DateTime expression to work we need to handle them as
                    filterExpression = filterExpression.Replace("DateTime.Parse", string.Empty);

                    for (int i = 0; i < countDate; i++)
                    {
                        //Create a new Regular expression that covers all the date types!
                        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(
                            "\\(\\\"" +
                                "\\d{1,2}[/-]\\d{1,2}[/-]\\d{2,4}" + //mm/dd/yyyy
                                "(?:" +
                                    "\\s*\\d{1,2}:\\d{1,2}:\\d{1,2}" + // hh:mm:ss
                                    "(?:" +
                                        "\\s*(?:AM|PM){0,2}" + // AM
                                    "){0,1}" +
                                "){0,1}" +
                            "\\\"\\)",
                            RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled
                            );

                        string date = regex.Match(filterExpression).ToString().Replace("\"", string.Empty).Replace("(", string.Empty).Replace(")", string.Empty);
                        DateTime d = Convert.ToDateTime(date);
                        filterExpression = regex.Replace(filterExpression, "@" + i.ToString(), 1);

                        listaDate[i] = d;
                    }
                }


                if (!String.IsNullOrEmpty(filterExpression))
                {
                    if (countDate > 0)
                    {
                        list = list.AsQueryable().Where(filterExpression, listaDate);
                    }
                    else
                    {
                        list = list.AsQueryable().Where(filterExpression);
                    }
                }



                result.Data = list.ToList();
                result.Count = list.Count();

            }
            catch (Exception e)
            {
                throw e;
            }

            return result;
        }



protected void OnNeedDataSource_OrdiniDashboard(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {

            DocNewGroupingTemplate docNewGroupingTemplate = new DocNewGroupingTemplate();
            docNewGroupingTemplate.GroupingTemplateDetailsList = new List<DocNewGroupingTemplateDetails>();
            ControllerGroupingTemplate ctrlGroupTemp = new ControllerGroupingTemplate();
            string sortExpression = String.Empty;

            Helper helper = new Helper();
            if (!helper.isValid(HttpContext.Current.Session))
            {
                return;
            }
            try
            {
                int groupingId = 0;
                if (HttpContext.Current.Session["GroupingTemplateComboBox"] != null)
                {
                    groupingId = Int32.Parse(HttpContext.Current.Session["GroupingTemplateComboBox"].ToString());
                    if(groupingId == -1)
                    {
                        docNewGroupingTemplate.GroupingName = "";
                        docNewGroupingTemplate.GroupingTemplateDetailsList = new List<DocNewGroupingTemplateDetails>();
                        docNewGroupingTemplate.GroupingTemplateDetailsList.Add(new DocNewGroupingTemplateDetails() { ColumnName = "DataScadenza", SortType = "Descending", GroupingSenderId = "dataScadenza", Type= "Data scadenza" });
                        docNewGroupingTemplate.GroupingTemplateDetailsList.Add(new DocNewGroupingTemplateDetails() { ColumnName = "StatoOrdineValue", SortType = "Descending", GroupingSenderId = "statoOrdineValue", Type = "Stato" });

                    }
                    else
                    {
                        docNewGroupingTemplate.GroupingName = ctrlGroupTemp.GetGroupingTemplateName(groupingId);
                        docNewGroupingTemplate.GroupingTemplateDetailsList = ctrlGroupTemp.GetGroupingTemplateDetailsList(groupingId);
                    }
                }

                string filterPeriod = HttpContext.Current.Session["FilterPeriod"].ToString();
                string filterExpression = String.Empty;

                if (filterPeriod != "Nessuno")
                {
                    string ricercaPerPeriodo = HttpContext.Current.Session["RicercaPerPeriodo"].ToString();
                    string fromDate = HttpContext.Current.Session["From"].ToString();
                    string toDate = HttpContext.Current.Session["To"].ToString();
                    DateTime currentDate = DateTime.Now;

                    if (ricercaPerPeriodo != "Personalizzato")
                    {
                        HttpContext.Current.Session.Add("From", String.Empty);
                        HttpContext.Current.Session.Add("To", String.Empty);
                        fromDate = String.Empty;
                        toDate = String.Empty;
                    }


                    if (!String.IsNullOrEmpty(filterPeriod) && !String.IsNullOrEmpty(ricercaPerPeriodo) && filterPeriod != "Nessuno")
                    {

                        switch (ricercaPerPeriodo)
                        {
                            case "Oggi":
                                filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{currentDate.Date}\")) AND ({filterPeriod} <= DateTime.Parse(\"{currentDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59)}\"))";
                                break;
                            case "Ieri":
                                currentDate = DateTime.Now.AddDays(-1);
                                filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{currentDate.Date}\")) AND ({filterPeriod} <= DateTime.Parse(\"{currentDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59)}\"))";
                                break;

                            case "QuestaSettimana":
                                DateTime monday = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek + 1);
                                filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{monday.Date}\")) AND ({filterPeriod} <= DateTime.Parse(\"{currentDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59)}\"))";
                                break;

                            case "QuestoMese":
                                DateTime month = DateTime.Today.AddDays(-(int)DateTime.Today.Day + 1);
                                filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{month.Date}\")) AND ({filterPeriod} <= DateTime.Parse(\"{currentDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59)}\"))";
                                break;

                            case "SettimanaScorsa":
                                DateTime mondayOfLastWeek = currentDate.AddDays(-(int)currentDate.DayOfWeek - 6);
                                DateTime sundayOfLastWeek = currentDate.AddDays(-(int)currentDate.DayOfWeek);
                                filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{mondayOfLastWeek.Date}\")) AND ({filterPeriod} <= DateTime.Parse(\"{sundayOfLastWeek.Date.AddHours(23).AddMinutes(59).AddSeconds(59)}\"))";
                                break;
                            case "MeseScorso":
                                DateTime lastMonth = new DateTime(currentDate.Year, currentDate.Month, 1);
                                DateTime first = lastMonth.AddMonths(-1);
                                DateTime last = lastMonth.AddDays(-1);
                                filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{first.Date}\")) AND ({filterPeriod} <= DateTime.Parse(\"{last.Date.AddHours(23).AddMinutes(59).AddSeconds(59)}\"))";
                                break;
                            case "Personalizzato":
                                if (!String.IsNullOrEmpty(fromDate) && !String.IsNullOrEmpty(toDate))
                                    filterExpression = $"({filterPeriod} >= DateTime.Parse(\"{fromDate}\")) AND ({filterPeriod} <= DateTime.Parse(\"{toDate}\"))";
                                break;

                            case "Nessuno":
                                filterExpression = String.Empty;
                                break;

                            default:
                                filterExpression = String.Empty;
                                break;
                        }
                    }
                }


                ResultData result = GetOrdiniListForDashboard(filterExpression);

                if (groupingId != 0)
                {

                    OrdiniDashboard_Grid.MasterTableView.GroupByExpressions.Clear();
                    foreach (var item in docNewGroupingTemplate.GroupingTemplateDetailsList)
                    {
                        GridGroupByField field = new GridGroupByField();
                        field.FieldName = item.ColumnName;
                        field.HeaderText = item.Type;
                        if (item.SortType == "Ascending")
                            field.SortOrder = GridSortOrder.Ascending;
                        else if (item.SortType == "Descending")
                            field.SortOrder = GridSortOrder.Descending;
                        else
                            field.SortOrder = GridSortOrder.None;
                        GridGroupByField selectfield = new GridGroupByField();
                        selectfield.FieldName = item.ColumnName;
                        selectfield.HeaderText = item.Type;
                        selectfield.FormatString = "{0:dd/MM/yyyy}";
                        GridGroupByExpression ex = new GridGroupByExpression();
                        ex.GroupByFields.Add(field);
                        ex.SelectFields.Add(selectfield);
                        OrdiniDashboard_Grid.MasterTableView.GroupByExpressions.Add(ex);
                        
                    }                  

                    HttpContext.Current.Session.Add("GroupingTemplateComboBox", 0);
                }

                if (result.Count > 0)
                {
                    OrdiniDashboard_Grid.DataSource = result.Data;

                    
                }
                else
                {
                    OrdiniDashboard_Grid.DataSource = new List<MyOrdDashboard>();
                }

            }
            catch (Exception exe)
            {
                throw exe;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 03 Apr 2020, 12:16 AM

Hi Tamara,

The Items collection of RadGrid always holds the items that are on the current page.

GridDataItemCollection items = RadGrid1.Items;

foreach (GridDataItem item in items)
{
    // some logic
}

 

The following articles will help you get a better understanding:

Kind regards,
Doncho
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Tamara
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or