Neo
Neo

Reputation: 16239

check grid value using jquery

gridid = myGrid

Name Status
aa   Open
bb   Close

I want to check weather in Status column there is Open status already present or not.

If yes then alert("already there ")

I tried like

  function CheckDraftStatus() {
   var index = $("#myGrid thead tr > *").filter(function () {
                  return 'Status' == $.trim($(this).text())
              }).index();

    $('#myGrid tbody tr td:nth-child(' + (index + 1) + ')').text(function (i, text) {
    if  ($.trim(text) == 'Open')  {return true;}             
    else {return false}
    });
}

correct me or any other code please?

Upvotes: 0

Views: 515

Answers (1)

DontVoteMeDown
DontVoteMeDown

Reputation: 21465

Well, try using :contains selector:

var result = $("#myGrid tbody tr td:nth-child(" + (index + 1) + "):contains('Open')");

return result.length > 0 ? true : false;

See this fiddle.

UPDATE: To use many contains you will have to use filter(), like:

var tds = $("#myGrid tbody tr td:nth-child(" + (index + 1) + ")");
tds.filter(":contains('Open')");

See this fiddle.

Upvotes: 1

Related Questions