# Count number of Lines in cell

**URL:** <https://community.glideapps.com/t/count-number-of-lines-in-cell/78135>\
**Category:** Ask for Help\
**Created:** [November 22, 2024, 3:32pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135 "2024-11-22T15:32:33Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 22, 2024, 3:32pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/1 "2024-11-22T15:32:33Z")

</div>

I have a text entry, and I’d like to count the number of lines in that text entry, for example:

Test1  
Test2  
Test3  
Test4  
Test5

Would output as 5,

I tried doing word count,

But the issue is if there is multiple words on a line it adds those words to the word count.

Any idea on how you would just count number of lines?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [November 22, 2024, 3:33pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/2 "2024-11-22T15:33:53Z")

</div>

You could use a Split Text column, splitting on a line break, then use a Rollup to get a count.  
Alternatively, a small JavaScript snippet would do the job.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [November 22, 2024, 3:37pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/3 "2024-11-22T15:37:07Z")

</div>

> [@Duncan\_Tilka](#):
>
> Test1  
> Test2  
> Test3  
> Test4  
> Test5

I’d probably go for the JavaScript option:

```auto
return p1.split('\n').length;

```

 ![CleanShot 2024-11-22 at 23.36.06@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/f/cffb0d259d1f4b15a2f57cf196f4c504cca0f5b1.png)

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 22, 2024, 3:39pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/4 "2024-11-22T15:39:01Z")

</div>

Thank you so much that Javascript function works perfectly!!

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 26, 2024, 5:12pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/5 "2024-11-26T17:12:32Z")

</div>

Hi Darren,

Thank you for your suggestion—it worked perfectly to show the count correctly! However, I’ve noticed an issue: while it displays in real time on a computer, it doesn’t update in real time on mobile.

I’ve already ensured the phone app is updated to the latest version, but for some reason, the JavaScript function isn’t reflecting changes in real time on mobile.

Do you have any suggestions for achieving this more easily using Glide’s computed columns?

I really appreciate your help—thank you!

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [November 26, 2024, 7:35pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/6 "2024-11-26T19:35:34Z")

</div>

I’ve never had javascript fail to update as expected on desktop or mobile. I’d be curious to know more about your setup. Is the column you feed into the javascript a basic text column? Usually when a parameter value changes, that triggers the javascript to rerun.

Are you inside of an Add or Edit form by any chance?

Have you tried Darren’s other solution to see if it works any better?

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [November 27, 2024, 12:08am UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/7 "2024-11-27T00:08:02Z")

</div>

I recall Duncan having syncing problems before, not once but twice.

> [@Glide App Not Updating on Phone](https://community.glideapps.com/t/glide-app-not-updating-on-phone/73219):
>
> Right before the end of the last billing cycle I noticed the changes I was making on my Glide app in the browser was not updating to reflect the changes on my iphone, once the billing cycle reset then it updated the app on my phone with the new changes. Now the changes that I make in the browser are not updating to my phone… I’ve tried: -Resyncing with the connected google sheets -Clearing Safari Website data, cookies, cache on iPhone settings, -Deleting the bookmarked app from my home scre…

> [@App Not Publishing Updates](https://community.glideapps.com/t/app-not-publishing-updates/73840):
>
> UPDATE: I tried clicking “Unpublish app” then turn it back on, but Now the app is showing “not Found” on chrome and on ios… This seems like a glitch or a bug, and I haven’t been able to get ahold of support… Please any help would be greatly appreciated!! Original post: Hi there, my app isn’t reflecting updates on my iphone that I see in the app. At first I thought that it could be an issue with cookies/browser on my phone side, but I’m seeing the issues on the app itself. It won’t publish…

I wonder if it’s the same problem this time. He suggested here that he uses “too many rows and columns”.

> [@App Not Publishing Updates](https://community.glideapps.com/t/app-not-publishing-updates/73840/4):
>
> So after unpublishing, it finally let me republish and it synced, but after talking with support it seems to be an issue of the amount of rows and column I’ve been using, going to clean it up and see how it does!

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 27, 2024, 12:31pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/8 "2024-11-27T12:31:37Z")

</div>

Yes, I believe the issue could indeed be related to the number of rows and columns used in my app. The app syncs perfectly when I make changes, but I’m wondering if the JavaScript function isn’t displaying the line count due to the volume of rows/columns or perhaps another underlying issue.

Here’s how I’ve set it up: the JavaScript function automatically updates the line count and displays that number as the title text beneath the text entry. This works flawlessly on desktop but doesn’t show up on mobile. Interestingly, when I use a simpler setup—like a word count function to display the word count as the title text—it works on both desktop and mobile without any issues.

It seems like the complexity of handling the line count might be the factor here, but I’d appreciate any insights or suggestions you might have.

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 27, 2024, 12:36pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/9 "2024-11-27T12:36:07Z")

</div>

![Screenshot 2024-11-27 at 7.33.51 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/3/032efc0c02adf281cc3a9948f9e506b839d5a3be.png)

The number from the JavaScript column is placed as the text title to display the count. For now, I’ve reverted to simply using the word count column since the number is close enough, though not exact (in cases where there are multiple words per line).

Here’s the issue: while the JavaScript function calculates and shows the correct line count in the Glide table, when I set it to display as the title, it only appears correctly on desktop, not on mobile. However, all other app changes are syncing perfectly, so the sync itself doesn’t seem to be the problem.

Interestingly, there’s no issue when I use the word count column instead of the JavaScript column to display the number as the title—this works fine on both desktop and mobile. It seems the problem arises specifically with the JavaScript column in combination with the mobile display.

I’d appreciate any advice on resolving this!

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [November 27, 2024, 1:07pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/10 "2024-11-27T13:07:17Z")

</div>

Is this one specific mobile device, or do you have the same problem on other mobile devices as well? I wonder if the javascript is crashing. I’ve seen that happen on rare occasions if bad or null data is being passed into the javascript and it can’t handle it properly. I’ve had cases where I’ve needed to refresh the browser to get it to run again. In those cases, I usually wrap my code in a try/catch so it can gracefully handle uncaught errors.

Try this once.

```auto
try {
  return p1.split('\n').length
} catch {
  return 0;
}

```

If that doesn’t work, you still have Darren’s alternative method which should work just as well if not better. All the javascript solution does is perform the count with one column while the other method uses two columns. Not that much of a difference.

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 27, 2024, 2:24pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/11 "2024-11-27T14:24:26Z")

</div>

Thank you for your insights! To answer your first question, this issue is currently happening on one specific mobile device, as I haven’t tested it on others yet. It’s possible that null or unexpected data is causing the JavaScript to behave this way, as you mentioned.

As for Darren’s method, I’m trying to use the **Split Text** column to split on a line break and then applying a **Rollup** to count the lines. I’ve tried splitting on `/n` and `\n`, but I’m not sure if I’m missing something here. Could you clarify the exact delimiter for the Split Text column or if there’s an additional step in the Rollup configuration? I want to ensure I’m implementing it correctly.

 ![Screenshot 2024-11-27 at 9.22.54 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/d/adeeece5a912ed3627ac75008ef903d2a7837bca.png)  
 ![Screenshot 2024-11-27 at 9.22.28 AM](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/9/1/9133e19b3f950318efeac6b7209940df2db511ce.png)

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [November 27, 2024, 2:30pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/12 "2024-11-27T14:30:20Z")

</div>

> [@Duncan\_Tilka](#):
>
> I’ve tried splitting on `/n` and `\n`,

Just press the Enter key as a carriage return. You don’t need any special character combinations for the split character. Enter is all you need.

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 27, 2024, 2:32pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/13 "2024-11-27T14:32:18Z")

</div>

Wow that was easy! Thank you for your help Jeff (and Darren)! 😁

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [November 27, 2024, 5:09pm UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/14 "2024-11-27T17:09:58Z")

</div>

I played around some more and it seems like the javascript column does not play well with carriage returns. Not sure why, or if I’m missing something obvious. Normally it should work.

The fix would involve replacing all carriage returns with some other kind of delimiter using a template column before passing that into a javascript column to split on that delimiter. Kind of pointless at that point, since the alternative method works better.

---

<div class="post-metadata">

**Author:** ![Duncan\_Tilka](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/duncan_tilka/32/62069_2.png) [@Duncan\_Tilka](https://community.glideapps.com/u/Duncan_Tilka)\
**Post date:** [November 28, 2024, 9:22am UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/15 "2024-11-28T09:22:32Z")

</div>

I see, well, I’m glad we’ve got the other solution in the meantime! Thanks so much for helping troubleshoot this—it’s much appreciated! 😊

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [December 5, 2024, 9:22am UTC](https://community.glideapps.com/t/count-number-of-lines-in-cell/78135/16 "2024-12-05T09:22:45Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
