Author Topic: Using variable in search method  (Read 2975 times)

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Using variable in search method
« on: March 10, 2016, 05:52:04 pm »
I am using a variable containing column name in search method. The code is:

                        // check for deleted records
                        if (res.deleteList.length > 0) {                           
                            for (i = 0; i < res.deleteList.length; i++) {
                                var objd = res.deleteList;
                                var coln = objd.Name;
                                var dvals = objd.Ids;
                                for (j = 0; j < dvals.length; j++) {
                                    var rowList = grid1.search({ row: { coln : dvals[j] } }, true);
                                    alert(rowList.length);
                                    // remove the row from grid

                                }
                            }
                        }

It is not returning the matched rows. How can I get the row from grid using the variables containing the field name and value?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Using variable in search method
« Reply #1 on: March 10, 2016, 10:20:00 pm »
In your code, the key name 'coln' is passed as such without substituting it with objd.Name.

The correct way is:

Code: [Select]
var row = {};
row[ coln ] = dvals[ j ];
//now it can be passed to the method:
var rowList = grid1.search({
  row: row,
  first: true
);

Digital Logix

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Using variable in search method
« Reply #2 on: March 11, 2016, 04:49:39 am »
Thanks it works.

A bracket was missing in the last line:

Code: [Select]
var row = {};
row[ coln ] = dvals[ j ];
//now it can be passed to the method:
var rowList = grid1.search({
  row: row,
  first: true
});