简体   繁体   中英

setcellvalue not working on all pages in JQWidget grid

I am using a JQWidget grid with paging to display table data, and I am replacing the values in one column with a string. This works fine for the initial page, but when I open the next page in the table I no longer get the string replacements, only the original value.

My home page uses this code, which works as expected ('A' and 'W' are replaced by 'newString' and 'newString2' in the table):

            $("#jqxgrid").bind("bindingcomplete", function (event) {

            var numrows = $("#jqxgrid").jqxGrid('getrows');
            for (i = 0; i < numrows.length; i++) {
                var value = $("#jqxgrid").jqxGrid('getcellvalue', i, 'column');
                if (value == 'W') {

                    $("#jqxgrid").jqxGrid('setcellvalue', i, 'column', 'newString');
                }
                else if (value == 'A') {
                    $("#jqxgrid").jqxGrid('setcellvalue', i, 'column', 'newString2');

            }

        });

I tried a few ideas for the new page, such as placing the above binding function into a loop based on the number of pages:

        var paginginfo = $("#jqxgrid").jqxGrid('getpaginginformation');
          for (i = 0; i < paginginfo.pagescount; i++) { ...

and I also tried putting the binding function inside another function tied to the page change event:

          $("#jqxgrid").bind("pagechanged", function (event) {


                $("#jqxgrid").bind("bindingcomplete", function (event) { ...

but neither of these worked. Perhaps 'numrows' is limiting setcellvalue to the first page? Thanks //

The "binding function" is not a function, it is an event which is raised usually once the binding is completed, to in general you tried to bind to an event within another event and that normally results in nothing. You loop code - for (i = 0; i < numrows.length; i++) {... would probably not work in case of virtual paging, because the loop should be from the start index to the end index and the start index wouldn't be 0 on the second page.

I found this workaround..I am not sure if this is really foolproof, but it seems to work so far..if you know a more precise solution please post...

        $("#jqxgrid").bind("bindingcomplete", function (event) {
           var paginginfo = $("#jqxgrid").jqxGrid('getpaginginformation');
           var pagenum = paginginfo.pagenum;
           var pagesize = paginginfo.pagesize;
           var pageRows = (pagenum + 1) * pagesize;

            for (var i = 0; i < pageRows; i++) {
                var value = $("#jqxgrid").jqxGrid('getcellvalue', i, 'currTrafDir');
                if (value == 'W') { ...... 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM