jQWidgets Forums

Forum Replies Created

Viewing 15 posts - 31 through 45 (of 68 total)
  • Author
    Posts

  • Pietervk
    Participant

    Hi Hristo,
    the statusExaminer variable is a global variable that is filled when the user selects a row in the current grid. By pressing the button, the UI goes to another tab with a second grid, that should be filtered based on that variable. I checked and it has the correct value.

    There is no error message.

    Thx

    Pieter


    Pietervk
    Participant

    Hello Hristo,
    The Paging en Filtering is working fine when I do it manually as in the demo thank you. To make sure, I moved the FormatData to DataAdapter. There is no difference to the result

    My problem is with the API filter, that does not work:

    
      var filtergroup = new $.jqx.filter();
      var filterEx = filtergroup.createfilter('stringfilter', statusExaminer, 'contains');
      $('#jqxgridEx').jqxGrid('addfilter', 'UserName', filterEx);
      $("#jqxgridEx").jqxGrid('applyfilters');
    

    The filter is not added to the jqxgridEx with the above.
    Thanks

    Pieter


    Pietervk
    Participant

    Thanks, I made this fiddle. It does reproduce another issue I am having. It works with a mouse, but on a mobile the date does not get captured.

    On a mobile, fill in 1-10-1980 and click on the calendar (or anywhere else) notice the date is no longer in 1980.

    http://jsfiddle.net/petitbarzun/zmc93263/7/

    I will try to reproduce the height issue later.

    Thanks

    Pieter


    Pietervk
    Participant

    Hi Admir,
    thanks for the additional information. As I do not get an email when someone posts on this forum, I did not see your post earlier, which is unfortunate.

    Since some of the data that needs to be sorted or filtered needs to be decrypted first, I can’t use a SQL query. However, when I did some tests earlier, I found that it does not really make a difference when you sort and filter in the query, or whether you do that in the server code. It makes a huge difference in user perceived performance when the paging is handled server side (virtual mode) compared to client side.

    Below the code I use to filter the items server side. The code is reusable. It accepts the jsonData coming from the grid query, and a list of row classes. It returns a filtered list of classes, and in the ref count parameter, the total number of records.

    
            public static List<T> FilterItems<T>(string jsonData, List<T> allItems, ref int count)
            {
                int pageSize = 10;
                int pageNum = 0;
                 if (jsonData != "{}")
                {
    
                    JToken token = JObject.Parse(jsonData);
    
                    List<JToken> filterGroups = token.SelectToken("filterGroups").Children().ToList();
                     pageSize = (int)token.SelectToken("pagesize");
                    pageNum = (int)token.SelectToken("pagenum");
    
                     string sortField = (string)token.SelectToken("sortdatafield") ?? "";
                    string sortOrder = (string)token.SelectToken("sortorder") ?? "";
                 
                    //filter all items of class T in the List<T> allItems
                    if (sortField != "")
                    {
                        if (sortOrder == "asc")
                        {
                            allItems = (from p in allItems
                                        orderby (p.GetType().GetProperty(sortField).GetValue(p))
                                        select p).ToList();
    
                        }
                        else if (sortOrder == "desc")
                        {
                            allItems = (from p in allItems
                                        orderby (p.GetType().GetProperty(sortField).GetValue(p)) descending
                                        select p).ToList();
                        }
                    }
                    if (filterGroups.Count > 0)
                    {
                        List<T> filteredItems = allItems;
                        for (int j = 0; j < filterGroups.Count; j++)
                        {
                            List<JToken> filters = filterGroups[j].SelectToken("filters").Children().ToList();
    
                            List<T> filterGroup = filteredItems;
                            List<T> filterGroupResult = new List<T>();
                            for (int i = 0; i < filters.Count; i++)
                            {
                                string filterLabel = (string)filters[i].SelectToken("label");
                                string filterValue = (string)filters[i].SelectToken("value");
                                string filterDataField = (string)filters[i].SelectToken("field");
                                string filterCondition = (string)filters[i].SelectToken("condition");
                                string filterType = (string)filters[i].SelectToken("type");
                                string filterOperator = (string)filters[i].SelectToken("operator");
    
                                List<T> currentResult = new List<T>();
    
                                switch (filterCondition)
                                {
                                    case "NOT_EMPTY":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)) != null)
                                                         select p).ToList();
                                        break;
                                    case "NOT_NULL":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString() != "")
                                                         select p).ToList();
                                        break;
                                    case "NULL":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)) == null)
                                                         select p).ToList();
                                        break;
                                    case "EMPTY":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString() == "")
                                                         select p).ToList();
                                        break;
                                    case "CONTAINS_CASE_SENSITIVE":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().Contains(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "CONTAINS":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().IndexOf(filterValue, StringComparison.CurrentCultureIgnoreCase) != -1)
                                                         select p).ToList();
                                        break;
                                    case "DOES_NOT_CONTAIN_CASE_SENSITIVE":
                                        currentResult = (from p in filterGroup
                                                         where (!(p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().Contains(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "DOES_NOT_CONTAIN":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().IndexOf(filterValue, StringComparison.CurrentCultureIgnoreCase) == -1)
                                                         select p).ToList();
                                        break;
                                    case "EQUAL_CASE_SENSITIVE":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString() == filterValue)
                                                         select p).ToList();
                                        break;
                                    case "EQUAL":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().IndexOf(filterValue, StringComparison.CurrentCultureIgnoreCase) == 0)
                                                         select p).ToList();
                                        break;
                                    case "NOT_EQUAL_CASE_SENSITIVE":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString() != filterValue)
                                                         select p).ToList();
                                        break;
                                    case "NOT_EQUAL":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().IndexOf(filterValue, StringComparison.CurrentCultureIgnoreCase) != 0)
                                                         select p).ToList();
                                        break;
                                    case "GREATER_THAN":
                                        currentResult = (from p in filterGroup
                                                         where (float.Parse(p.GetType().GetProperty(filterDataField).GetValue(p).ToString()) > float.Parse(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "LESS_THAN":
                                        currentResult = (from p in filterGroup
                                                         where (float.Parse(p.GetType().GetProperty(filterDataField).GetValue(p).ToString()) < float.Parse(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "GREATER_THAN_OR_EQUAL":
                                        currentResult = (from p in filterGroup
                                                         where (float.Parse(p.GetType().GetProperty(filterDataField).GetValue(p).ToString()) >= float.Parse(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "LESS_THAN_OR_EQUAL":
                                        currentResult = (from p in filterGroup
                                                         where (float.Parse(p.GetType().GetProperty(filterDataField).GetValue(p).ToString()) <= float.Parse(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "STARTS_WITH_CASE_SENSITIVE":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().StartsWith(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "STARTS_WITH":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().StartsWith(filterValue, StringComparison.CurrentCultureIgnoreCase))
                                                         select p).ToList();
                                        break;
                                    case "ENDS_WITH_CASE_SENSITIVE":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().EndsWith(filterValue))
                                                         select p).ToList();
                                        break;
                                    case "ENDS_WITH":
                                        currentResult = (from p in filterGroup
                                                         where ((p.GetType().GetProperty(filterDataField).GetValue(p)).ToString().EndsWith(filterValue, StringComparison.CurrentCultureIgnoreCase))
                                                         select p).ToList();
                                        break;
                                }
    
                                if (filterOperator == "or")
                                {
                                    filterGroupResult.AddRange(currentResult);
                                }
                                else
                                {
                                    filterGroup = currentResult;
                                    filterGroupResult = currentResult;
                                }
                            }
                            filteredItems = filterGroupResult;
                        }
                        allItems = filteredItems;
    
                    }
                }
                count = allItems.Count;
                List<T> items = new List<T>();
                int startpageindex = pageNum * pageSize;
              
                int pagecount = (startpageindex + pageSize <= count) ? pageSize : count - startpageindex;
                items = allItems.GetRange(startpageindex, pagecount);
                return items;
            }

    This is Controller method called by the grid as defined in the source object:

    
     [HttpGet]
     public async Task<string> getUsers([FromQuery] string jsonData)
     {
               
                List<StateUser> allUsers = await GetUserList();          //get a list of objects that we want displayed in the grid
               
                int count = 0;
    
                StateUserData stateUserData = new StateUserData()
                {
                    Tests = FilterItems(jsonData, allUsers , ref count),  //filter the data
                    TotalRecords = count
                };
              
    
                return JsonConvert.SerializeObject(stateUserData );
    
     }
    in reply to: Ajax Fail callback Ajax Fail callback #94148

    Pietervk
    Participant

    Yes, I know, but I can’t find the delete post button 🙂

    in reply to: Ajax Fail callback Ajax Fail callback #94079

    Pietervk
    Participant

    Never mind, found it.

    $(document)
        .ajaxError(function (event, jqXHr, settings) {
               if (jqXHr.status == 401) {
               //fail gracefully
            }
        })

    This allows me to do away with the loadserverdata call alltogether


    Pietervk
    Participant

    Try to add an event on your grid:

     $("#updateMyActivity").jqxGrid( {
    ....
        source: dataAdapter,
        theme: 'bootstrap',
        width: '100%',
        rendergridrows: function (params) {
                    return params.data;
                },

    and one on the dataAdapter:

    `dataAdapter = new $.jqx.dataAdapter(source,
    {
    contentType: ‘application/json; charset=utf-8’,
    autoBind: false,
    loadComplete: function (records) {

    },`
    You can then see in these events if the expected content actually arives or not.

    Rebinding the grid will not update your table though.


    Pietervk
    Participant

    It is a bit hard to read, if you could use the Code button to preserve layout, it makes it a lot easier.

    From what I understand from the code, in updateActivityLogTable you are doing a clear on the grid, and than completely reinitialize it. I am not sure how that looks on the UI, but it is not needed.

    Try this: only initialize the grid once on the page, and in updateActivityLogTable, do not clear the grid, but instead update it:

    
       $('#myActivityGrid').source = dataAdapter ;
        $("#myActivityGrid").jqxGrid("updatebounddata");
    

    This will bind the data and refresh the grid to the current state of the source. The grid cells get an inplace update, rather than a complete wipe and reload.
    You may need to place a var dataAdapter on a level that it still exists in updateActivityLogTable
    When you do this, you also do not need to show and hide the loadelement, as it is automatic on update.

    I assume your problem with the details also goes away when you do this.


    Pietervk
    Participant

    Thanks Hristo,
    what is the issue with filtering and sorting with 15s updates? I have not seen any issues, the json data for filtering and sorting is passed to the server. I query the full set on the server, and then use filtering and sorting to get the set used for the grid display, as found in the example.

    I just made the following change to your example, rather than looping through the set, I let Linq do it, but I assume that wont make a big change

    count = allItems.Count;
    List<T> items = new List<T>();
    int startpageindex = pageNum * pageSize;
    int pagecount = (startpageindex + pageSize <= count) ? pageSize : count - startpageindex;
    items = allItems.GetRange(startpageindex, pagecount);
    return items;

    But I am curious about your warning on the update with other operations.


    Pietervk
    Participant

    The only solution I have found is to ensure the width of the columns does not exceed the width of the grid. I use fixed column width and tweak it to the pixel.
    If you have found another solution, I would be happy to know.


    Pietervk
    Participant

    For me this works:
    1) not recreate the dataAdapter, just use the existing variable
    2) refresh:

    
    function updateGrid() {
      if ($('#jqxgrid').is(":visible")) {
         $("#jqxgrid").jqxGrid({ source: dataAdapter });
         $('#jqxGrid').jqxGrid('updatebounddata',"cells");

    }
    }
    `

    in reply to: Losing a row Losing a row #93828

    Pietervk
    Participant

    Hi Hristo,
    Thank you for the tips, I have implemented these.

    Pieter

    in reply to: Losing a row Losing a row #93706

    Pietervk
    Participant

    Hello Hristo,
    They are in the database. The row was already missing in the grid before adding the row. I am adding the row in the database, I am not using the addrow method. But please do not focus on adding the row. All data is there on loadComplete, it is lost when rendergridrows is called.
    Here is most of the code:

       source = {
            datatype: "json",
            datafields: [
                { name: 'ClientLabel', type: 'string' },
                { name: 'SessionId', type: 'string' },
                { name: 'TestId', type: 'string' },
                { name: 'DtCreated', type: 'date', format: 'yyyy-MM-dd HH:mm' },
                { name: 'DtFirstLogin', type: 'date', format: 'yyyy-MM-dd HH:mm' },
                { name: 'DtLastSaved', type: 'date', format: 'yyyy-MM-dd HH:mm' },
                { name: 'Aq', type: 'string' },
                { name: 'Finished', type: 'bool' },
                { name: 'ReminderNeeded', type: 'int' },
                { name: 'Id', type: 'int' },
                { name: 'IntID', type: 'int' },
                { name: 'RepSent', type: 'bool' },
            ],
            async: true,
            id: 'Id',
            cache: false,
            type: "GET",
            root: 'Tests',
            url: 'GetTests',
    
            formatData: function (data) {
                data = JSON.stringify(data);
                return { "jsonData": data };
            },
            beforeprocessing: function (data) {
                source.totalrecords = data.TotalRecords;
            },
            sort: function (data) { $('#jqxgrid').jqxGrid('updatebounddata', 'sort'); },
            filter: function (data) { $('#jqxgrid').jqxGrid('updatebounddata', 'filter'); }
        };
     dataAdapter = new $.jqx.dataAdapter(source,
            {
                contentType: 'application/json; charset=utf-8',
                autoBind: false,
                loadComplete: function (records) {
                  //inspecting records here shows all records
                },
            }
        );
    
      $('#jqxgrid').on("bindingcomplete", function (event) {
           
            StatusGridDone = true;
            clearTimeout(refreshTim);
            refreshTim = setTimeout(refreshStatusGrid, 15000);
    
        });
       $(".jqxgrid").jqxGrid(
            {
                source: dataAdapter,
                width: StWidth,
                pageable: true,
                pagesize: pagesize,
                sortable: true,
                filterable: true,
                enabletooltips: true,
                columnsresize: true,
                columnsautoresize: true,
                pagesizeoptions: ['5', '10', '20', '30'],
                autoheight: true,
                theme: 'energyblue',
                columns: StColumns,
                virtualmode: true,
                rendergridrows: function (params) {
                    return params.data; //row is gone here
                },
    
            });
    
    function refreshStatusGrid() {
        if (StatusGridDone) {
          
            updateStatusGrid();
        }
        clearTimeout(refreshTim);
        refreshTim = setTimeout(refreshStatusGrid, 15000);
    }
    function updateStatusGrid() {
        if ($('#jqxgrid').is(":visible")) {
            $('#jqxgrid').source = dataAdapter;
            dataAdapter.dataBind();
            $('#jqxgrid').jqxGrid("updatebounddata", "cells");
        } else {
            clearTimeout(refreshTim);
    
        }
    }

    Thanks, Pieter

    in reply to: Losing a row Losing a row #93508

    Pietervk
    Participant

    Hi Hristo,
    sorry if my post was not clear.

    All rows are retrieved from the database and filtered, then on loadcomplete, all rows are still there. However in the rendergridrows function, one row has disappeared. So with all rows in the database, one gets lost after loadcomplete and before it is displayed, by the processing that is done in the grid.

    Thanks for looking in to this again.

    Pieter

    in reply to: Losing a row Losing a row #93387

    Pietervk
    Participant

    PS, I have added 4 rows, so now my row 6 that was lost is the 10th row. It shows on the second page as normal. However, when I change the page size to 20, the row disappears again!

Viewing 15 posts - 31 through 45 (of 68 total)