public static object RemoveNulls(this SortableJsOptions fixMe)
        {
            var t           = fixMe.GetType();
            var returnClass = new Dictionary <string, object>();

            foreach (var pr in t.GetProperties())
            {
                var val = pr.GetValue(fixMe);
                if (pr.PropertyType != typeof(Action <SortableJSEvent>) &&
                    val != null &&
                    !string.IsNullOrWhiteSpace(val.ToString()))
                {
                    returnClass.Add(pr.Name.Substring(0, 1).ToLowerInvariant() + pr.Name.Substring(1), val);
                }
            }

            return(returnClass);
        }
        public async Task Create(string elId, SortableJsOptions opt)
        {
            _opt = opt;

            await _jSRuntime?.InvokeAsync <object>("BlazorSortableJS.Create", _refId, elId, opt.RemoveNulls());

            //Register to all Events
            SortableJSEventHandler.OnChooseEvent   += OnChoose;
            SortableJSEventHandler.OnUnchooseEvent += OnUnchoose;
            SortableJSEventHandler.OnStartEvent    += OnStart;
            SortableJSEventHandler.OnEndEvent      += OnEnd;
            SortableJSEventHandler.OnAddEvent      += OnAdd;
            SortableJSEventHandler.OnUnchooseEvent += OnUpdate;
            SortableJSEventHandler.OnSortEvent     += OnSort;
            SortableJSEventHandler.OnRemoveEvent   += OnRemove;
            SortableJSEventHandler.OnFilterEvent   += OnFilter;
            SortableJSEventHandler.OnMoveEvent     += OnMove;
            SortableJSEventHandler.OnCloneEvent    += OnClone;
            SortableJSEventHandler.OnChangeEvent   += OnChange;
        }
Beispiel #3
0
        public async ValueTask <object> CreateAsync(string elId, SortableJsOptions opt)
        {
            _opt  = opt;
            _elId = elId;
            await _jSRuntime.InvokeAsync <string>("BlazorSortableJS.Create", RefId, elId, opt.RemoveNulls());

            //Register to all Events
            SortableJSEventHandler.OnChooseEvent   += OnChoose;
            SortableJSEventHandler.OnUnchooseEvent += OnUnchoose;
            SortableJSEventHandler.OnStartEvent    += OnStart;
            SortableJSEventHandler.OnEndEvent      += OnEnd;
            SortableJSEventHandler.OnAddEvent      += OnAdd;
            SortableJSEventHandler.OnUnchooseEvent += OnUpdate;
            SortableJSEventHandler.OnSortEvent     += OnSort;
            SortableJSEventHandler.OnRemoveEvent   += OnRemove;
            SortableJSEventHandler.OnFilterEvent   += OnFilter;
            SortableJSEventHandler.OnMoveEvent     += OnMove;
            SortableJSEventHandler.OnCloneEvent    += OnClone;
            SortableJSEventHandler.OnChangeEvent   += OnChange;

            return(default);
        public static object RemoveNulls(this SortableJsOptions fixMe)
        {
            var t           = fixMe.GetType();
            var returnClass = new Dictionary <string, object>();

            foreach (var pr in t.GetProperties())
            {
                var val = pr.GetValue(fixMe);
                if (pr.PropertyType == typeof(Action <SortableJSEvent>))
                {
                }
                else if (val is string && string.IsNullOrWhiteSpace(val.ToString()))
                {
                }
                else if (val == null)
                {
                }
                else
                {
                    returnClass.Add(pr.Name, val);
                }
            }
            return(returnClass);
        }