Filter a DataGrid.

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Filter a DataGrid.

Post by zaxos » Mon Aug 04, 2014 5:24 pm

this isnt a question, if anyone want to filter a datagrid her's what i did.
Filter button code:

Code: Select all

on mouseUp
   lock screen
   send dbConnect to me -- Populates the DataGrid with data
   put the dgData of group "DataGrid" into theDataB --  Puts the data of the DataGrid into a variable
   put the dgIndexes of group "DataGrid" into theIndexes -- Puts the Indexes of the DataGrid into a variable
   repeat for each item theIndex in theIndexes
      if theDataB[theIndex]["People"] contains field "filter" or theDataB[theIndex]["Country"] contains field "Filter" then -- If Array "People" or "Country" contains any of the text in field "filter" then it populates the DataGrid with this data
         put theDataB[theIndex]["People"] after theDataC[theIndex]["People"]
         put theDataB[theIndex]["Country"] after theDataC[theIndex]["Country"]
      end if
   end repeat
   set the dgData of group "DataGrid" to theDataC
   unlock screen
end mouseUp
Refresh button code:

Code: Select all

send dbConnect to me
Last edited by zaxos on Mon Aug 11, 2014 11:43 pm, edited 1 time in total.
Knowledge is meant to be shared.

sritcp
Posts: 431
Joined: Tue Jun 05, 2012 5:38 pm

Re: Filter a DataGrid.

Post by sritcp » Wed Aug 06, 2014 11:10 pm

Hi zaxos:

Code: Select all

if theDataB[theIndex]["People"] or theDataB[theIndex]["Country"] contains field "Filter" then
is only testing the second condition, not the first (it won't return a compilation error, so it will blindside you).

You really mean

Code: Select all

if theDataB[theIndex]["People"] contains field "Filter" or theDataB[theIndex]["Country"] contains field "Filter" then
Regards,
Sri.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10356
Joined: Wed May 06, 2009 2:28 pm

Re: Filter a DataGrid.

Post by dunbarx » Wed Aug 06, 2014 11:30 pm

Yes.

What Sri said.

Each snippet of a boolean must resolve independently. Be sure you understand this. In a button script:

Code: Select all

on mouseUp
   put "true" into xxx
   if xxx then answer "Valid"
end mouseUp
If you comment out the first line, you get nothing. This is because the engine actually does try to evaluate "if xxx", and sees it as shorthand for "if xxx is true". This is common parlance, and should also be made familiar to you.

So in your line of code, there is no error, because the evaluation is as follows:

Code: Select all

if theDataB[theIndex]["People"] is "true" or theDataB[theIndex]["Country"] contains field "Filter" then
But this is not what you wanted, correct? You wanted what Sri expanded for you.

Craig Newman

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Filter a DataGrid.

Post by zaxos » Mon Aug 11, 2014 11:42 pm

Thank you for you corrections guys! I didn't even know there was a mistake until now, never needed to filter the first field... i will update my code and the original post :)
Knowledge is meant to be shared.

Post Reply