Am I considered fulfilling postdoc duty in this situation? General question: 
I am a postdoc supported by a grant A. Is it OK for me to work with people not in the grant supporting me on a topic related to grant A, given that I will acknowledge the grant in all publications? Am I expected to include the PI as co-authors? 

Details:
I am supported by a grant A. Then I did some works related to grant A and got a publication with other individuals not in the grant A. I acknowledged the grant supporting me in the publication, but without including the PI of grant A as a co-author.

I already did this, it seems the PI of grant A is OK with that. But I am not sure if I am doing something wrong/unethical. I just wonder if it is commonly acceptable. I am doing that because we are not fit each other, I stay for family reason and will leave soon.
I don't see any ethical consideration as long as your PI is happy and you aren't violating any specific contractural arrangements from your funding. I think that is unlikely. Whether you need to list the PI or not is a different question, and depends on your field and somewhat on the PI. If the PI can help in your future career, it would be good to consider them as author, but my opinion is that would imply that they contribute something. 

But authorship of PIs and supervisors varies by field. 

And yes, acknowledge the grant and its funders.