|
| 1 | +@page "/" |
| 2 | +@using System.Data |
| 3 | +@using Oracle.ManagedDataAccess.Client |
| 4 | +@using Syncfusion.Blazor.PivotView |
| 5 | + |
| 6 | +<SfPivotView TValue="EmployeeDetails" Width="1000" Height="300" ShowFieldList="true"> |
| 7 | + <PivotViewDataSourceSettings TValue="EmployeeDetails" DataSource="@dataSource" ExpandAll=false EnableSorting=true> |
| 8 | + <PivotViewColumns> |
| 9 | + <PivotViewColumn Name="JOB" Caption="Designation"></PivotViewColumn> |
| 10 | + </PivotViewColumns> |
| 11 | + <PivotViewRows> |
| 12 | + <PivotViewRow Name="EMPLOYEE_NAME" Caption="Employee Name"></PivotViewRow> |
| 13 | + </PivotViewRows> |
| 14 | + <PivotViewValues> |
| 15 | + <PivotViewValue Name="SALARY" Caption="Salary"></PivotViewValue> |
| 16 | + <PivotViewValue Name="COMMISSION" Caption="Commission"></PivotViewValue> |
| 17 | + </PivotViewValues> |
| 18 | + <PivotViewFormatSettings> |
| 19 | + <PivotViewFormatSetting Name="SALARY" Format="C0"></PivotViewFormatSetting> |
| 20 | + <PivotViewFormatSetting Name="COMMISSION" Format="C0"></PivotViewFormatSetting> |
| 21 | + </PivotViewFormatSettings> |
| 22 | + </PivotViewDataSourceSettings> |
| 23 | + <PivotViewGridSettings ColumnWidth="120"></PivotViewGridSettings> |
| 24 | +</SfPivotView> |
| 25 | + |
| 26 | +@code { |
| 27 | + public List<EmployeeDetails> dataSource { get; set; } |
| 28 | + protected override void OnInitialized() |
| 29 | + { |
| 30 | + List<EmployeeDetails> employeeData = new List<EmployeeDetails>(); |
| 31 | + string connectionString = "<Enter your valid connection string here>"; |
| 32 | + OracleConnection connection = new OracleConnection(connectionString); |
| 33 | + connection.Open(); |
| 34 | + OracleCommand command = new OracleCommand("SELECT * FROM EMPLOYEES", connection); |
| 35 | + using (OracleDataReader reader = command.ExecuteReader()) |
| 36 | + { |
| 37 | + while (reader.Read()) |
| 38 | + { |
| 39 | + employeeData.Add(new EmployeeDetails() |
| 40 | + { |
| 41 | + DEPARTMENT_ID = Convert.ToInt32(reader["DEPARTMENT_ID"]), |
| 42 | + EMPLOYEE_ID = Convert.ToInt32(reader["EMPLOYEE_ID"]), |
| 43 | + EMPLOYEE_NAME = reader["EMPLOYEE_NAME"].ToString(), |
| 44 | + JOB = reader["JOB"].ToString(), |
| 45 | + MANAGER_ID = Convert.IsDBNull(reader["MANAGER_ID"]) ? null : Convert.ToInt32(reader["MANAGER_ID"]), |
| 46 | + SALARY = Convert.ToSingle(reader["SALARY"]), |
| 47 | + COMMISSION = Convert.IsDBNull(reader["COMMISSION"]) ? null : Convert.ToSingle(reader["COMMISSION"]), |
| 48 | + HIREDATE = Convert.ToDateTime(reader["HIREDATE"]) |
| 49 | + }); |
| 50 | + } |
| 51 | + } |
| 52 | + connection.Close(); |
| 53 | + this.dataSource = employeeData; |
| 54 | + } |
| 55 | + |
| 56 | + public class EmployeeDetails |
| 57 | + { |
| 58 | + public int EMPLOYEE_ID { get; set; } |
| 59 | + public string EMPLOYEE_NAME { get; set; } |
| 60 | + public string JOB { get; set; } |
| 61 | + public int? MANAGER_ID { get; set; } |
| 62 | + public Single SALARY { get; set; } |
| 63 | + public Single? COMMISSION { get; set; } |
| 64 | + public int DEPARTMENT_ID { get; set; } |
| 65 | + public DateTime HIREDATE { get; set; } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
0 commit comments