Ken_Sowyer Posted January 22, 2018 Share Posted January 22, 2018 Hello! How I get the onclick event of a button in a UnimDBListGrid? function beforeInit(sender, config) { config.itemTpl = '<div>'+ '<t>{0} </t>'+ '<button id={1} onclick="DEL_ITEM">X</button>'+ '</div>' } Thanks! Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 22, 2018 Share Posted January 22, 2018 Hello, Which edition and build are you using ?! Quote Link to comment Share on other sites More sharing options...
Ken_Sowyer Posted January 22, 2018 Author Share Posted January 22, 2018 1423, trial version Quote Link to comment Share on other sites More sharing options...
Ken_Sowyer Posted January 23, 2018 Author Share Posted January 23, 2018 Alright, here what I done: '<button id={1} onclick="myFunction()">X</button>'+ Then create a .js file with an ajaxRequest, adding to CustomFiles in the ServerModule. function myFunction(){ ajaxRequest(MyForm.form,"ExcluirItem",[]); } Then add the OnAjaxEvent to the form. if EventName = 'ExcluirItem' then myAct.Execute; I don't know if there's a simple way, but it's working. Quote Link to comment Share on other sites More sharing options...
powergov Posted March 27, 2018 Share Posted March 27, 2018 how to know "MyForm.form" ? my unigui form's name? example mainmform.listgrid1 ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 27, 2018 Share Posted March 27, 2018 Hi, how to know "MyForm.form" ? my unigui form's name? example mainmform.listgrid1 ? Sorry, Can you clarify your question? Quote Link to comment Share on other sites More sharing options...
powergov Posted March 27, 2018 Share Posted March 27, 2018 Hi, Sorry, Can you clarify your question? if my delphi form name is mainmform,my unimdblistgrid name is lst1 in lst1 unievents's beforeinit i write function beforeInit(sender, config) { config.itemTpl='<table style="width:100%;white-space: nowrap;vertical-align:middle;">'+ '<tr>'+ '<td >{0}</td>'+ '<td >{1}<input type="button" id="btn1" name="btn1" value="ClickMe" onclick="myFunction()"></td>'+ '<td >{2}</td>'+ '</tr></table>' } How to write the CustomFiles in the ServerModule ??? ==================== function myFunction(){ ajaxRequest(??????.????,"ExcluirItem",[]); } ======================= my form name is mainmform my unimdblistgrid name is lst1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 27, 2018 Share Posted March 27, 2018 Hi, You can use new Ext.XTemplate with functions Quote Link to comment Share on other sites More sharing options...
Sherzod Posted March 27, 2018 Share Posted March 27, 2018 Can help you: http://forums.unigui.com/index.php?/topic/7772-unimdblistgrid-xtemplate-values-from-store/&do=findComment&comment=39683 http://forums.unigui.com/index.php?/topic/4869-mobile-phonebook-mobile-app/&do=findComment&comment=53664 ... Quote Link to comment Share on other sites More sharing options...
x11 Posted May 21, 2020 Share Posted May 21, 2020 @Sherzod не могли бы вы подсказать? Я хочу добавить кнопки, с событиями, чтобы на сервер отправлять ID, т.е. значение из нулевого столбца {0} function beforeInit(sender, config){ config.loadMask=true; config.loadingText = 'загрузка...'; config.emptyText='даних немає'; config.grouped = false; config.selectedCls = ''; console.log(config); console.log(sender); console.log(this); config.itemTpl = new Ext.XTemplate('<table style="width:100%; white-space:nowrap; vertical-align:middle;">'+ '<tr>'+ '<td style="color:#2c81aa">ID {0}, ID на сайті: {13}</td>'+ '<td><input type="button" id="btn1" name="btn1" value="ClickMe" onclick="this.myFunction(????)"></td>'+ '</tr>'+ '<tr>'+ '<td>ДОЗ: {1}</td>'+ '</tr>'+ '<tr>'+ '<td>{2}</td>'+ '</tr>'+ '<tr>'+ '<td style="padding-top:3px;">{3}; {4}, {5}</td>'+ '</tr>'+ '</table>', { myFunction: function(val){ ajaxRequest(this, 'myFunction', ['val=' + val]) } } ); } Кнопка появляется. Но что и как передать в качестве параметра onclick="this.myFunction(????)" что написать вместо ???? Спасибо. Quote Link to comment Share on other sites More sharing options...
x11 Posted May 21, 2020 Share Posted May 21, 2020 Сейчас при клике я получаю ошибку Quote m:1 Uncaught TypeError: this.myFunction is not a function at HTMLInputElement.onclick (m:1) onclick @ m:1 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 21, 2020 Share Posted May 21, 2020 1 hour ago, x11 said: Я хочу добавить кнопки, с событиями, чтобы на сервер отправлять ID, т.е. значение из нулевого столбца {0} Ок, я проверю. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 21, 2020 Share Posted May 21, 2020 4 hours ago, x11 said: Но что и как передать в качестве параметра Может быть, так попробуете? function beforeInit(sender, config) { var me=sender; me.myFunction = function(id) { alert(id); }; var nm=config.id.replace('_id', ''); config.itemTpl = new Ext.XTemplate('<table style="width:100%; white-space:nowrap; vertical-align:middle;">'+ '<tr>'+ '<td style="color:#2c81aa">ID {0}, ID на сайті: {13}</td>'+ '<td><input type="button" id="btn1" name="btn1" value="ClickMe" onclick="'+ nm +'.myFunction({0});"></td>'+ '</tr>'+ '<tr>'+ '<td>ДОЗ: {1}</td>'+ '</tr>'+ '<tr>'+ '<td>{2}</td>'+ '</tr>'+ '<tr>'+ '<td style="padding-top:3px;">{3}; {4}, {5}</td>'+ '</tr>'+ '</table>' ); } 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted May 22, 2020 Share Posted May 22, 2020 ошибка Quote Uncaught TypeError: fmmmyobjects_dbgmyobjects_0.myFunction is not a function at HTMLInputElement.onclick (m:1) onclick @ m:1 При копировании убрал лишние знаки "?", т.к. появилось пара вопросительных знаков. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 22, 2020 Share Posted May 22, 2020 23 minutes ago, x11 said: При копировании убрал лишние знаки "?", т.к. появилось пара вопросительных знаков. Работает? Quote Link to comment Share on other sites More sharing options...
x11 Posted May 22, 2020 Share Posted May 22, 2020 нет, я же ошибку написал, чуть выше картинки смотрите Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 22, 2020 Share Posted May 22, 2020 36 minutes ago, x11 said: fmmmyobjects_dbgmyobjects_0 Вам знакомо это "имя"? Quote Link to comment Share on other sites More sharing options...
x11 Posted May 22, 2020 Share Posted May 22, 2020 да, это имя формы и имя сетки, у меня в настройках проект включено soControlNameAsId Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 22, 2020 Share Posted May 22, 2020 2 minutes ago, x11 said: в настройках проект включено soControlNameAsId Я проверю. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 22, 2020 Share Posted May 22, 2020 4 hours ago, x11 said: у меня в настройках... Другое решение, попробуйте: function beforeInit(sender, config) { config.itemTpl = new Ext.XTemplate('<table style="width:100%; white-space:nowrap; vertical-align:middle;">' + '<tr>' + '<td style="color:#2c81aa">ID {0}, ID на сайті: {13}</td>' + '<td><input class=".btn1" type="button" value="ClickMe" data-id="{0}"></td>' + '</tr>' + '<tr>' + '<td>ДОЗ: {1}</td>' + '</tr>' + '<tr>' + '<td>{2}</td>' + '</tr>' + '<tr>' + '<td style="padding-top:3px;">{3}; {4}, {5}</td>' + '</tr>' + '</table>' ); } function afterCreate(sender) { Ext.getCmp(sender.id).bodyElement.addListener('click', function(event, target) { if (target.getAttribute('class') === '.btn1') { alert(target.getAttribute('data-id')); } }, null, { delegate: 'table input' }); } 2 Quote Link to comment Share on other sites More sharing options...
x11 Posted May 22, 2020 Share Posted May 22, 2020 Работает. Большое Вам спасибо. Осталось прикрутить отправку аякс запроса Quote Link to comment Share on other sites More sharing options...
x11 Posted May 22, 2020 Share Posted May 22, 2020 function afterCreate(sender) { Ext.getCmp(sender.id).bodyElement.addListener('click', function(event, target) { if (target.getAttribute('class') === '.btn1') { ajaxRequest(this, "editid", [target.getAttribute('data-id')]); } }, null, { delegate: 'table input' }); } Что здесь может быть не так? Вижу, в консоли браузера отправляется запрос. Но в программу не приходит. Т.е. событие TfmmMyObjects.dbgMyObjectsAjaxEvent() не срабатывает Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 22, 2020 Share Posted May 22, 2020 ajaxRequest(sender,... пробовали? 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted May 22, 2020 Share Posted May 22, 2020 О! Точно. Ещё раз спасибо. Помогло! 1 Quote Link to comment Share on other sites More sharing options...
x11 Posted May 23, 2020 Share Posted May 23, 2020 Не могу понять, почему кнопки уехали влево. Подскажите, как сделать, чтобы кнопки были выровнены по правому краю. Спасибо. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.