Skip to content

Commit

Permalink
extend aggrid
Browse files Browse the repository at this point in the history
  • Loading branch information
hacsko-adam-evo committed Mar 13, 2024
1 parent 7338510 commit 4e54d47
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
49 changes: 34 additions & 15 deletions SiemensIXBlazor/Components/AGGrid/AGGrid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,38 @@

namespace SiemensIXBlazor.Components.AGGrid
{
public partial class AGGrid
{
[Parameter, EditorRequired]
public string Id { get; set; } = string.Empty;

public async Task<IJSObjectReference?> CreateGrid(GridOptions options)
{
if (Id == string.Empty)
{
return null;
}

return await JSRuntime.InvokeAsync<IJSObjectReference?>("agGridInterop.createGrid", Id, JsonConvert.SerializeObject(options));
}
}
public partial class AGGrid
{
[Parameter]
public EventCallback OnCellClicked { get; set; }

[Parameter, EditorRequired]
public string Id { get; set; } = string.Empty;

private DotNetObjectReference<AGGrid>? dotNetHelper;

public async Task<IJSObjectReference?> CreateGrid(GridOptions options)
{
if (Id == string.Empty)
{
return null;
}

dotNetHelper = DotNetObjectReference.Create(this);

return await JSRuntime.InvokeAsync<IJSObjectReference?>("agGridInterop.createGrid", dotNetHelper, Id, JsonConvert.SerializeObject(options));
}

public async Task<object?> GetSelectedRows(IJSObjectReference gird)
{
return await JSRuntime.InvokeAsync<Object>("agGridInterop.getSelectedRows", gird);

}

[JSInvokable]
public async Task OnCellClickedCallback()
{
await OnCellClicked.InvokeAsync();
}
}
}
7 changes: 7 additions & 0 deletions SiemensIXBlazor/Components/AGGrid/ColumnDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public class ColumnDefs
public int? MaxWidth { get; set; }
[JsonProperty("minWidth")]
public int? MinWidth { get; set; }
[JsonProperty("hide")]
public bool? Hide { get; set; }
[JsonProperty("lockPosition")]
public string? LockPosition { get; set; }
[JsonProperty("suppressMovable")]
public bool? SuppressMovable { get; set; }


}
}
2 changes: 1 addition & 1 deletion SiemensIXBlazor/Components/Drawer/Drawer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
id="@Id"
show="@Show"
full-height="@FullHeight"
close-on-click-outside="@CloseOnClickOutside.ToString().ToLower()"
close-on-click-outside="@CloseOnClickOutside"
max-width="@MaxWidth"
min-width="@MinWidth"
width="@Width"
Expand Down
21 changes: 15 additions & 6 deletions SiemensIXBlazor/SiemensIXBlazor_NpmJS/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ window.toggleSystemTheme = (useSystemTheme) => {

// AGGrid
window.agGridInterop = {
createGrid: function (elementId, gridOptions) {
const grid = new Grid(document.getElementById(elementId), JSON.parse(gridOptions))
console.log(JSON.parse(gridOptions))
return grid;
dotnetReference: null,
createGrid: function (dotnetRef, elementId, gridOptions) {
let parsedOption = JSON.parse(gridOptions);

window.agGridInterop.dotnetReference = dotnetRef;
parsedOption.onCellClicked = function (event) {
dotnetRef.invokeMethodAsync('OnCellClickedCallback');
};

return new Grid(document.getElementById(elementId), parsedOption);
},
setData: function (grid, data) {
grid.api.setRowData(data);
}
grid.gridOptions.api.setRowData(data);
},
getSelectedRows: function (grid) {
return grid.gridOptions.api.getSelectedRows();
},
}

0 comments on commit 4e54d47

Please sign in to comment.