The trial of a claim and the offsets or counterclaims, if any, shall be to the court without a jury. However, the court may, in its discretion, either on its own motion or upon the motion of any party, submit the matter to a jury. In the event that the amount of the claim or a counterclaim exceeds the sum stated in section 631.1, subsection 1, either party shall be entitled to a jury trial, if a written demand is made as provided in the rules of civil procedure in relation to the trial of ordinary actions.