solved Form Table IDs/Data

nate
@nate
11 years ago
917 posts
When building a table inside a module view or a form; how can I add an ID or data to the table row?

I'll be adding rows to this table via AJAX.

What I need to do is run a jQuery check to prevent duplicate entries into the table, so I need to identify each row.
updated by @nate: 02/26/14 07:42:55PM
brian
@brian
11 years ago
10,149 posts
Natedogg265:
When building a table inside a module view or a form; how can I add an ID or data to the table row?

I'll be adding rows to this table via AJAX.

What I need to do is run a jQuery check to prevent duplicate entries into the table, so I need to identify each row.

It depends - are you using a DataStore or writing your own queries to a custom table? I'd recommend using a UNIQUE KEY where you simply can do:

INSERT INTO table ... ON DUPLICATE KEY UPDATE ...

As that will:

1) assure there are no duplicates
2) simplify your logic

https://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 01/27/14 07:44:44AM
nate
@nate
11 years ago
917 posts
I guess I wasn't very clear in my post. The table I am adding to is just aform table.

$dat[1]['title'] = 'id';
    $dat[1]['width'] = '5%;';
    $dat[2]['title'] = 'user';
    $dat[2]['width'] = '10%;';
    $dat[3]['title'] = 'percentage';
    $dat[3]['width'] = '5%;';
    $dat[4]['title'] = '';
    $dat[4]['width'] = '75%;';
    $html .= ujMultiItem_form_table_header($dat);

That's just a peace of the code to show you what I mean by table.

Steve has a js function that populates the table rows. I want to identify them so we don't add duplicates. I basically just need each row to have data that can be read via js.

I was thinking something like:
$dat[2]['data'] = $_rt['unique_id'];
brian
@brian
11 years ago
10,149 posts
You'll have to hack this a little bit by adding your own id's in - i.e.

$dat[1]['class'] = '" id="u'. $_rt['unique_id'];

Basically you're overriding the "class" param by closing it with a double quote, then specifying the actual DOM id, without a closing double quote.

Let me know if that helps.

Thanks!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
brian
@brian
11 years ago
10,149 posts
Note I started that id name with a "u" - this is because if unique_id is numeric, then they are invalid for using as a DOM id - all DOM id's must start with a letter. You can use whatever you want though as long as the id starts with a letter.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
nate
@nate
11 years ago
917 posts
Substring here I come.

Thanks Brian. You're by far the best support team ever.
brian
@brian
11 years ago
10,149 posts
Natedogg265:
Substring here I come.

Thanks Brian. You're by far the best support team ever.

No problem ;)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
nate
@nate
11 years ago
917 posts
It's working, As I'm sure you expected. lol
brian
@brian
11 years ago
10,149 posts
Natedogg265:
It's working, As I'm sure you expected. lol

Glad to hear that :)


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

Tags